使用数据表从postgresql显示数据时遇到问题,这是我的问题。
我的桌子上有666个条目,但在第一页中,数据表显示一条消息未找到匹配的记录,即使数据表显示它显示666个条目中的1到10个,
当我尝试转到下一页(第2页)时,消息消失了,显示了11到20条记录的数据。
然后当我尝试转到第三页时,数据表仍显示以前的数据(来自第二页),但是21到30条记录的数据也显示,即使数据表显示它显示为21到30 666条目。
当我进入下一页时,它出现了,之前的数据仍显示在数据表中。
你介意告诉我解决问题的方法吗?因为我已经坚持了将近一个星期。 感谢。
这是我的服务器端处理代码,
`
// initilize all variable
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
//define index of column
$columns = array(
0 =>'terminal_id',
1 =>'tid',
2 => 'merchant_id',
3 => 'encrypted_ktm'
);
$where = $sqlTot = $sqlRec = "";
// check search value exist
if( !empty($params['search']['value']) ) {
$where .=" WHERE ";
$where .=" ( tid::text LIKE '%".$params['search']['value']."%' ";
$where .=" OR merchant_id::text LIKE '%".$params['search']['value']."%' ";
$where .=" OR encrypted_ktm LIKE '%".$params['search']['value']."%' )";
}
// getting total number records without any search
$sql = "SELECT terminal_id, tid, merchant_id, encrypted_ktm FROM terminal";
$sqlTot .= $sql;
$sqlRec .= $sql;
//concatenate search sql if value exist
if(isset($where) && $where != '') {
$sqlTot .= $where;
$sqlRec .= $where;
}
$sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." OFFSET ".$params['length']." ";
$queryTot = pg_query($sqlTot);
$totalRecords = pg_num_rows($queryTot);
$queryRecords = pg_query($sqlRec);
//iterate on results row and create new index array of data
while( $row = pg_fetch_row($queryRecords) ) {
$data[] = $row;
}
$json_data = array(
"draw" => intval( $params['draw'] ),
"recordsTotal" => intval( $totalRecords ),
"recordsFiltered" => intval($totalRecords),
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
这是我的Javascript代码
$( document ).ready(function() {
$('#employee_grid').DataTable({
"processing": true,
"serverSide": true,
/*"ajax": "response.php".*/
"ajax":{
url :"response.php", // json datasource
type: "post", // type of method , by default would be get
error: function(){ // error handling code
$("#employee_grid_processing").css("display","none");
}
}
});
});