Im trying to parse pager data and grid data through a json response into a jqgrid.
Here is the php file that creates a json file wich contains all these data (pager+grid data)
if(!$sidx) $sidx =1;
$result = mysql_query("SELECT COUNT(*) AS count FROM logs");
$row = mysql_fetch_array($result);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
$pages_array = array("page"=> $page , "total" => $total_pages , "records" => $count);
array_push($return_array,$pages_array);
// Getting data for jqGrid table
$data = mysql_query("SELECT * FROM logs ORDER BY log_id DESC");
if(mysql_num_rows($data))
{
while($row = mysql_fetch_array($data))
{
$row_array['rows']['log_id'] = $row['log_id'];
$row_array['rows']['ip'] = $row['ip'];
$row_array['rows']['hostname'] = $row['host'];
$row_array['rows']['log'] = $row['input'];
$row_array['rows']['date'] = $row['date'];
array_push($return_array,$row_array);
}
}
echo json_encode($return_array);
With this php code i retrieve a json file like this :
[{"page":"1","total":2,"records":"34"},
{"rows":{"log_id":"108","ip":"127.0.0.1","hostname":"","log":"having 1=1--","date":"09-06-2013 22:05:57"}},
{"rows":{"log_id":"107","ip":"127.0.0.1","hostname":"","log":"\/\/","date":"09-06-2013 22:05:57"}},
{"rows":{"log_id":"106","ip":"127.0.0.1","hostname":"","log":"**/","date":"09-06-2013 22:05:55"}},
{"rows":{"log_id":"105","ip":"127.0.0.1","hostname":"","log":"+and+","date":"09-06-2013 22:05:55"}}]
But this is wrong structure. In a post here in stackoverflow user Musa said that the structure must be like this :
{
"page": 2,//current page
"total": 2,//number of pages
"records": 11,//# of records in total
"rows": [//array of data
{
"id": "101",//id for this row of data
"cell": [
"101",
"Sundale",
"OTTP",
"652",
"6",
"65",
"656665",
"986346654",
"823343454",
"554332"
]
}
]
}
Can someone help me fix my code so the structure that json response be right ?
Thanks for any help!