Click here to Skip to main content
14,699,089 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello guys,
I am getting a problem in getting JSON data from a php file (PHP file is using database i.e MySQL).
Code is mentioned below.

   $("ul").append("<li>Name : "+this['name']+"</li><br/> ");
   $("ul").append("<li>Age : "+this['age']+"</li><br/> ");
   $("ul").append("<li>Company : "+this['company']+"</li><br/> ");

include_once ('db.php');

$sql="Select * from people";
$res=  mysql_query($sql);

while($row=  mysql_fetch_array($res))
    array_push($result, array('name' => $row[0],
    echo json_encode(array("result"=>$result));

Update : Problem is that jquery doesn't gives any output on the browser. Yes, I am posting every row of the query output so I inserted "echo" in while loop.
Updated 7-Mar-14 2:01am
Maarten Kools 5-Mar-14 9:04am
You didn't mention your problem. But I would suggest moving the echo json_encode call out of your while loop, otherwise you're outputting for each row.
Killzone DeathMan 6-Mar-14 5:05am
Agree :)
Akkywadhwa 7-Mar-14 7:02am
Hello Maarten,
I have updated my question. Kindly check this.
Maarten Kools 7-Mar-14 7:21am
If you are outputting every row of the query your json isn't going to be correct. You can debug your JavaScript in various browsers with built in tools or extensions (in the case of Firefox)
Internet Explorer[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900