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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:49:41+00:00 2026-06-15T04:49:41+00:00

Why this json encode format is not working .If I write it outside of

  • 0

Why this json encode format is not working .If I write it outside of the all brackets.Then it works,but get only one row.Plz help

$sql=mysqli_query($database,"SELECT * FROM com  ORDER by time DESC");
while($row=mysqli_fetch_array($sql)){
        $mid=$row['id'];
        $text=$row['text'];

        if($text) {
            $response=array();

            $response['msg']=$text;
            $response['id']=$id;
            echo json_encode($response);
        }
}
    //$response=array();

    // $response['msg']=$text;
    // $response['id']=$mid;
    // echo json_encode($response);

Jquery for getting above results.

function com(id){
    $.post('load.php', {tocom:id},function(data) {
        var json = eval('(' + data + ')');
        if(json['msg'] != "") {
            var msg=json['msg'];
            var fro=json['id'];
            $("#msg).html(fro+msg);
        }
      });
}
  • 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-15T04:49:42+00:00Added an answer on June 15, 2026 at 4:49 am

    You are not giving one json response, but as much response as you have iterations in your while.

    The good syntax should be :

    PHP :

    $sql=mysqli_query($database,"SELECT * FROM com  ORDER by time DESC");
    $final_response = array();
    while($row=mysqli_fetch_array($sql)){
        $mid=$row['id'];
        $text=$row['text'];
    
        if($text) {
            $response=array();
            $response['msg']=$text;
            $response['id']=$id;
            $final_response[] = $response;
        }
    
    }
    echo json_encode($final_response);
    

    JS :

    function com(id){
    
        $.post('load.php', {tocom:id},function(data) {
            $("#msg").html('');
            var json = eval('(' + data + ')');
            $.each(json, function(i, row) {
               if(row['msg'] != "") {
                   var msg=row['msg'];
                   var fro=row['fro'];
                   $("#msg").append(fro+msg);
               }
            });
        });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create a json encode in PHP like this: $get = mysql_query(SELECT * FROM
I am parsing this JSON file (correctly, it works with the UITextFields): {longitude:[37.786793,39.388528],latitude:[-122.395416,-78.887734]} ind
{: attachment-2,: attachment-1} I am getting this JSON-encoded string (or an oher format... let
this auto complete extender is working perfectly but i dont whats the reason its
How can I get rid of the brackets below for json processing? [{success:true,filename:bialding_and_rebialding_plymouth02.jpg},{success:true,filename:bialding_and_rebialding_plymouth03.jpg},{success:true,filename:bialding_and_rebialding_plymouth04.jpg}] The
jQuery $.ajax() does not seem to work correctly with IE8 but it is working
This piece of valid json (it has been generated using php's json_encode): {html:form is
How do I transform this JSON object: context:{#text:[Most Visited Pages , Hall Residents Advanced
How can i convert this JSON array: This is a serialized JSON array 2012-06-18
i have this JSON object: {error:null, result:[{id:1234567890, count:1, recipients: [u3848, u8958, u7477474 ], dateCreated:2012-06-13T09:13:45.989Z

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.