数据按我预期加载。页数也计算在内。但是当我更改页码时,会出现相同的数据。
这是 jQgird 代码:
$("#list").jqGrid({
url: "classes/classesController.php",
datatype: "json",
mtype: "POST",
postData: {method:"getLogsList"},
colNames: ["Id","Ip", "Hostname", "Log", "Ημ/νια"],
colModel: [
{ name: "log_id", index:"log_id", width: 100, sortable:false, hidden:true},
{ name: "ip", index: "ip", width: 130, searchoptions:{sopt:['eq']} },
{ name: "hostname", index:"hostname", width: 180 , searchoptions:{sopt:['eq']}},
{ name: "log", index:"log", width: 180, align: "right", searchoptions:{sopt:['eq']}},
{ name: "date", index:"date", width: 180, align: "right", searchoptions:{sopt:['eq']}}
],
jsonReader: { root: "rows", page: "page", total: "total", records: "records", repeatitems: true, cell: "cell", id: "id",},
caption: "Logs",
gridview: true,
rownumbers: true,
height: 'auto',
shrinkToFit: false,
rowNum:2,
pager: '#gridpager'
});
这里是php部分:
init_mysql();
$response = new stdClass();
// 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;
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
// Getting data for jqGrid table
$data = mysql_query("SELECT * FROM logs ORDER BY log_id DESC");
$i = 0;
if(mysql_num_rows($data))
{
while($row = mysql_fetch_array($data))
{
$response->rows[$i]['id']=$i+1;
$response->rows[$i]['cell']=array('log_id'=>$row['log_id'],'ip'=>$row['ip'],'hostname'=>$row['host'],'log'=>$row['input'],'date'=>$row['date']);
$i++;
}
}
echo json_encode($response);
为什么会这样?正如我在请求中看到的,一切正常。第一页变成了第二页,以此类推..
method=getLogsList&_search=false&nd=1371379260922&rows=33&page=2&sidx=&sord=asc