Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7758635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:24:38+00:00 2026-06-01T13:24:38+00:00

Here I have a simple php script which displays some values from a database

  • 0

Here I have a simple php script which displays some values from a database in json format.

$source = $_GET['source'];

$query = mysql_query("SELECT * FROM images WHERE big_thumb = '" . $source . "'");

$results = array();

while($row = mysql_fetch_array($query))
{
   $results[] = array(
      'title' => $row['title'],
      'date' => $row['upload_date'],
      'time' => $row['upload_time']
   );
}

$json = json_encode($results);

echo $json;

This displays fine, heres an output example:

[{"title":"Torus","date":"2012-04-04","time":"23:06:14"}]

Then when an image is clicked this jquery is called:

var image_src = $(this).attr("alt"); // <= This works fine

    $.ajax({
        url: 'inc/get_image_details.php',
        data: {source : image_src},
        dataType: "json",
        success: function(data)
        {
            title = data.title;
            alert(title);

            date = data.date;
            alert(date);

            time = data.time;
            alert(time);
        }
    });

However, the (title, date & time) variables display as ‘undefined’ in the alert box.
I’ve tried multiple ways of implementing the ajax call and the same thing happens every time.
It is the first time I’ve tried it alright but I can’t figure it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:24:41+00:00Added an answer on June 1, 2026 at 1:24 pm

    Your json string has an array format. You need to access the json object properties like this

    title = data[0].title;
    alert(title);
    
    date = data[0].date;
    alert(date);
    
    time = data[0].time;
    alert(time);
    

    If you control the json format and an array is not necessary, use a json object with this format.

    {"title":"Torus","date":"2012-04-04","time":"23:06:14"}
    

    In this case you can keep your code as it is now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple script which inserts values from a text file into a
I have a really simple PHP script here,which simply loads several libraries (6 or
I have a simple java project (adapted from the example here ), which is
I have a script that performs some simple editing which works fine, the problem
I have a very simple PHP script which creates favicon.ico form jpg/gif/png uploaded file.
I have a simple script which I have included here. the select query works
i have to create a simple script which retrieves the mails from gmail account
Here is example which I have try <?php include 'spider/classes/simple_html_dom.php'; $html = new simple_html_dom();
Im sure this is simple but newbie here. I have 5 URLS cards.php&type=one cards.php&type=two
I have simple algorithm that clean the whitespace from half string until end. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.