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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:49:04+00:00 2026-06-01T22:49:04+00:00

This is a little bit of a hard problem to explain, so ill show

  • 0

This is a little bit of a hard problem to explain, so ill show you instead. If you look below you will see valid JSON.

{
    "data":{
        "0":{
            "action_id":"1",
            "date":"2012-04-10 15:07:38",
            "action_type":"1",
            "action_text":"Some one got blamed!"
        },
        "1":{
            "action_id":"2",
            "date":"2012-04-10 16:18:05",
            "action_type":"1",
            "action_text":"Testing multiple items for AJAX"
        },
        "total":2,
        "ajax_message":"Success",
        "ajax_status":"0",
        "success":"true"
    }
}

But for the application were using it cannot handle the “0”: ,”1″, it instead just wants it comma separated .

My current code to generate this is:

while ($r = mysql_fetch_assoc($q)) {
        $array[] = $r;
    }
json_encode($array);

Fairly simple and raw stuff at the moment. But i think i may have to write a json_encode for myself in order for it to print it like this…..

Any help would be greatly appreciated

NOTE: This is a valid form(written by hand):

{
"data": [
{
"action_id": "1",
"date": "2012-04-10 15:07:38",
"action_type": "1",
"action_text": "Some one got blamed!",
"fb_id": "760775384"
},
{
"action_id": "2",
"date": "2012-04-10 16:18:05",
"action_type": "1",
"action_text": "Testing multiple items for AJAX",
"fb_id": "760775384"
}
],
"total": 2,
"ajax_message": "Success",
"ajax_status": "0",
"success": "true"
}
  • 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-01T22:49:06+00:00Added an answer on June 1, 2026 at 10:49 pm

    The problem is that your numeric keys (0, 1) are at the same level in the hash as named keys (total, ajax_message, etc). Instead of doing this:

    $a = array();
    while ($r = mysql_fetch_assoc($q)){
        $a[] = $r;
    }
    $a['key'] = value;
    

    Do this:

    $a = array();
    $a['rows'] = array();
    while ($r = mysql_fetch_assoc($q)){
        $a['rows'][] = $r;
    }
    $a['key'] = value;
    

    If every key in the array ($a['rows'] in this example) is numeric, json_encode() will output it as a [{list}, {like}, {this}]

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

Sidebar

Related Questions

its a little bit hard to understand. in the header.php i have this code:
This may be a little bit of a hard one to pin down exactly,
It's a little bit hard to find an appropriate title for this. I think
My problem is a little bit hard but simple. I have (or there is)
This little bit of syntax has been a bit of a confusion for me
Maybe this sounds a little bit crazy, but I need to come up with
This question may seem a little bit stackoverflow-implementation specific, but I have seen a
This might be a little bit odd question, but Im trying to figure out
This might be a little bit picky, but in the iPad SplitViewController setup, there
This is a deceptively tricky little bit of HTML/JS that has either me or

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.