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
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.