您好我正在jQuery DataTables Server Side
网站上使用PHP
。我能够显示所有数据,搜索/过滤数据。但它只在第一页上工作。当我尝试转到Second Page
及以上时,No matching records found
显示且没有数据。请检查我的下面的代码,不确定问题是否在我的查询中。感谢
test.php的
$fetch_data = $dtQuery->make_datatables();
$data = array();
foreach($fetch_data as $row)
{
$sub_array = array();
$sub_array[] = $row['ApplNo'];
$sub_array[] = $row['BLNo'];
$data[] = $sub_array;
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $dtQuery->get_all_data(),
"recordsFiltered" => $dtQuery->get_filtered_data(),
"data" => $data
);
echo json_encode($output);
ViewPage.php
<table id="myTable">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
</tr>
</thead>
</table>
QueryTable.php
public function make_datatables(){
$offset = $_POST['start'];
$limit = $_POST['length'];
$filter = $_POST["search"]["value"];
$extractdata = "SELECT *
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY CreationDate DESC) AS RowNum, *
FROM MANIFESTBOL WHERE (ApplNo LIKE '%$filter%' OR BLNo LIKE '%$filter%')
) AS RowConstrainedResult
WHERE RowNum >= '$offset'
AND RowNum < '$limit'";
return $STH = $this->connection->query($extractdata);
}
public function get_filtered_data(){
$filter = $_POST["search"]["value"];
$extractdata = "SELECT COUNT(*)
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY CreationDate DESC) AS RowNum, *
FROM MANIFESTBOL WHERE (ApplNo LIKE '%$filter%' OR BLNo LIKE '%$filter%')
) AS RowConstrainedResult";
return $STH = $this->connection->num_rows($extractdata);
}
public function get_all_data()
{
$count = "SELECT COUNT(ApplNo) as count FROM MANIFESTBOL";
$result = $this->connection->count_all_results($count);
return $result["count"];
}
的script.js
var dataTable = $('#myTable').DataTable({
"iDisplayLength": 10,
"aLengthMenu": [[10, 25, 50, 100, 500, 1000, -1], [10, 25, 50, 100, 500, 1000, "All"]],
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:'webfiles/Test.php',
type:"POST"
},
"columnDefs":[
{
"targets":[0],
"orderable":false,
},
]
});