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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:56:10+00:00 2026-05-25T23:56:10+00:00

Edit: Solved using the below suggestion of removing: echo ‘{results:’.json_encode($arr).’}’; and replacing with echo

  • 0

Edit:
Solved using the below suggestion of removing:echo '{"results":'.json_encode($arr).'}';
and replacing with echo json_encode($arr);

This combined with replacing these lines:

var items = [];
        $.each(data, function(key, val) {
            $.each(val, function(key, val)
            {
                    //Test insert into box using customer number
                $("#chatbox").html(val.number);
            });
        });

with

$.each(data, function(key, val) {
$("#chatbox").html(this.number);
});

Made it work, I can now access the object data using the this followed by the property I want.

End Edit

Hi could anyone help me with these JSON feed. I am almost there with it (I think) however whenever I put this feed into JQuery it is picked us as a string rather than as an array of JSON objects and I can’t figure out why.

The PHP to create the feed:

<?php
session_start();

include 'connect.php';

    $number = $_SESSION['number'];

    $query = "SELECT * FROM $tableName WHERE number='$number'";

    $result = mysql_query($query, $sqlCon);

    $arr = array();
    while($obj = mysql_fetch_object($result)) {
        $arr[] = $obj;
    }

    if (count($arr) == 0)
    {
        echo "Your reference number is: $number";
    } else {
        echo '{"results":'.json_encode($arr).'}';
    }
?>

The returned JSON looks like this:

{"results":[{"id":"40","number":"466741","message":"dsfdsv","date":"2011-10-05","time":"00:28:32"},{"id":"41","number":"466741","message":"sacsac","date":"2011-10-05","time":"00:30:17"}]}

What I instead want is:

[{"id":"40","number":"466741","message":"dsfdsv","date":"2011-10-05","time":"00:28:32"},{"id":"41","number":"466741","message":"sacsac","date":"2011-10-05","time":"00:30:17"}]

Or a return value which would allow me to iterate over the objects.

The JQuery I’m reading it with:

$.getJSON('get.php', function(data) {

var items = [];
    $.each(data, function(key, val) {
        $.each(val, function(key, val)
        {
                //Test insert into box using customer number
            $("#chatbox").html(val.number);
        });
    });
});

I’m guessing my problem is the way in which I’m creating the JSON feed but I’m just stuck and cant figure out how to fix it.

Any help would be appreciated, thanks.

  • 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-05-25T23:56:11+00:00Added an answer on May 25, 2026 at 11:56 pm

    You should set the headers from PHP to specify that it is json content. This isn’t 100% required but good practice and you’ll see the content-type parsed correctly in tools like firebug.

    header('Content-type: application/json');
    

    You are wrapping your json content with a results key that that you aren’t looking for in your javascript so you either need to remove that part or look for that your javascript. Since you say you want the array and not the object with the results key/value just replace echo '{"results":'.json_encode($arr).'}'; with echo json_encode($arr);

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

Sidebar

Related Questions

Edit: I have solved this by myself. See my answer below I have set
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
EDIT: Paul has solved this one below. Thanks! I'm trying to resample (upscale) a
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
EDIT 3: Solved. See below. EDIT 2: I think Chadwick's on the right track
SOLVED: See my solution below! using aspx with C# code behind. I have the
EDIT: Solved this myself - obviously won't work as sorting the dataTable doesn't sort
Edit : Solved, there was a trigger with a loop on the table (read
Edit: Solved. Hi, I'm starting with Qt, I try to connect a slot to

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.