Jump to content

JqGrid json structure help


netpumber

Recommended Posts

I have this php code for counting the pages number and retrieve data from database, but something is going wrong with the pager as i can see.

Specifically i think that there is a problem with the json file structure.

Here is the php code:

public function getLogsList($page,$limit,$sidx,$sord)
{
init_mysql();

$return_array = array();
$row_array = array();

// Getting pages number (for jqGrid pager)

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;

$row_array['page'] = $page;
$row_array['total'] = $total_pages;
$row_array['records'] = $count;

array_push($return_array,$row_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['log_id'] = $row['log_id'];
$row_array['ip'] = $row['ip'];
$row_array['hostname'] = $row['host'];
$row_array['log'] = $row['input'];
$row_array['date'] = $row['date'];

array_push($return_array,$row_array);
} 
}

echo json_encode($return_array);
}

The json file looks like this :

[{"page":"1","total":2,"records":"34"},{"page":"1","total":2,"records":"34","log_id":"108","ip":"127.0.0.1","hostname":"","log":"having 1=1","date":"09-06-2013 22:05:57"},{"page":"1","total":2,"records":"34","log_id":"107","ip":"127.0.0.1","hostname":"","log":"\/\/","date":"09-06-2013 22:05:57"},.....}]

as you can see page , total and records are printed every time and thats why i think that something is going wrong with the structure of json file.

 

I saw in a forum that the json file must have this structure but i cannot make it look like this

{
"page": "1",
"total": 1,
"records": "6",
"rows": [
{
"head": {
"student_name": "Mr S. Jack ",
"year": 2007

},
"sub": [
{
"course_description": "Math ",
"date": "22-04-2010",
"number": 1,
"time_of_add": "2:00",
"day": "today"
}
]

}
]
}

Can you help me on this issue ?

 

Thanks in advance

 
Link to comment
https://forums.phpfreaks.com/topic/279202-jqgrid-json-structure-help/
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.