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 8074865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:47:59+00:00 2026-06-05T14:47:59+00:00

The array values return as ‘undefined’ when printed, even though by using print_r($items) I

  • 0

The array values return as ‘undefined’ when printed, even though by using print_r($items) I can see that the array is not empty. What could be the issue here?

MySQL:

Table called ‘nights’ with columns called ‘name’, ‘price’, ‘day’, ‘queue jump’, ‘closing’ and ‘doors’. They are all populated.

eventinfo.php:

<?php

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

include('functions.php');
connect();

$night = $_POST['club'];
// this echos fine
$night = mysql_real_escape_string($night);

$query = "SELECT * FROM nights WHERE name = '$night'";

    $result = mysql_query($query);
    $items = array();

    if($result && mysql_num_rows($result) > 0) { 
        while ($row = mysql_fetch_array($result)) { 
        $items[] = array("price"=>$row['price'], "day"=>$row['day'], "queue jump"=>$row['queue jump'], "closing"=>$row['closing'], "doors"=>$row['doors']);
        }
    } 

    mysql_close(); 
    // convert into JSON format and print

    echo json_encode($items);
?>

JS:

<script type="text/javascript">

    $(document).ready(function() {
// for simplicity's sake, but ultimately I'd like to load all the information
            $('#right_inside').html('<h2>' + $('#club').val() + '</h2>');
    });

    $('#club').change(function(event) {
        $.ajax({
            type: "post",
            url: "eventinfo.php",
            data:  $(this).serialize(),
            success: function(data) {
                $('#right_inside').html('<h2>' + $('#club').val() + '</h2><p>Day: ' + data.day + '</p>');
                },
            dataType: "json"
        });
    });

</script>
  • 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-05T14:48:01+00:00Added an answer on June 5, 2026 at 2:48 pm

    You have got your JSON structure wrong. Data is actually an array:

    Try changing data.day to data[0].day

    Note: You should use JSON.stringify(data) in your ajax success to see the structure of your JSON.

    $.ajax({
      type: "post",
      url: "eventinfo.php",
      data:  $(this).serialize(),
      success: function(data) {
         alert(JSON.stringify(data));
         //or
         console.log(JSON.stringify(data));
      },
       dataType: "json"
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i return my output in ArrayCollection? values = array(); while($row = mysql_fetch_array($result))
When I compare two array values I see two strings that look the same.
How can I get the array values return by a Json format in twitter.
How would I filter through an array and return values that contain a certain
Is it possible for a function to return two values? Array is possible if
How can I add all of my array values together in PHP? Is there
I'm working with two-dimensional array-values that should be inserted into a ArrayList. But this
Before I sort I can access array values by key correctly. var a=[]; a['1']={'id':'1','aaa':'xxx'}
I decided to get shuffled values from array. for that i used this function,
im trying to insert an array values into the file using foreach.. and if

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.