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);
}
});
}