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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<div class="sfcode">public function getLogsList($page,$limit,$sidx,$sord)<br /> {<br /> init_mysql();<br /> <br /> $return_array = array();<br /> $row_array = array();<br /> <br /> // Getting pages number (for jqGrid pager)<br /> <br /> if(!$sidx) $sidx =1;<br /> $result = mysql_query("SELECT COUNT(*) AS count FROM logs");<br /> $row = mysql_fetch_array($result);<br /> $count = $row['count'];<br /> <br /> if( $count >0 ) {<br /> $total_pages = ceil($count/$limit);<br /> } else {<br /> $total_pages = 0;<br /> }<br /> <br /> if ($page > $total_pages) $page=$total_pages;<br /> $start = $limit*$page - $limit;<br /> <br /> $row_array['page'] = $page;<br /> $row_array['total'] = $total_pages;<br /> $row_array['records'] = $count;<br /> <br /> array_push($return_array,$row_array);<br /> <br /> // Getting data for jqGrid table<br /> <br /> $data = mysql_query("SELECT * FROM logs ORDER BY log_id DESC");<br /> <br /> if(mysql_num_rows($data))<br /> {<br /> while($row = mysql_fetch_array($data))<br /> {<br /> <br /> $row_array['log_id'] = $row['log_id'];<br /> $row_array['ip'] = $row['ip'];<br /> $row_array['hostname'] = $row['host'];<br /> $row_array['log'] = $row['input'];<br /> $row_array['date'] = $row['date'];<br /> <br /> array_push($return_array,$row_array);<br /> }<br /> }<br /> <br /> echo json_encode($return_array);<br /> }</div> |
The json file looks like this :
|
1 |
[{"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.
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top