Forum
12:22
08/07/2011
I have this php code for counting the number of pages
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 each time and
that why i think that something is going wrong with the structure of json file.
Is there any way to fix it ?
Thanks.
23:41
08/07/2011
I've change a little the code but still have to change more..
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);
Most Users Ever Online: 715
Currently Online:
46 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66