按照标题所述,我有以下代码使用datatables服务器端处理来获取表中的数据,但最终没有返回结果:
include(mysqli_db.php);
$request = $_REQUEST;
$col = array(
0 => 'id',
1 => 'name',
2 => 'phone',
3 => 'ic_pp_no',
4 => 'passport_no',
5 => 'email',
6 => 'address1',
7 => 'address2',
8 => 'country',
9 => 'pp_expiry_date',
10 => 'created_date'
);
$q = "SELECT * FROM account";
$sql = $mysqli->query($q);
$totalData = $sql->num_rows;
$totalFilter = $totalData;
$data = array();
while($row = $sql->fetch_object()){
$subdata = array();
$subdata[] = $row->name;
$subdata[] = $row->phone;
$subdata[] = $row->ic_pp_no.$row->passport_no;
$subdata[] = $row->email;
$subdata[] = $row->address1.$row->address2;
$subdata[] = $row->country;
$subdata[] = $row->id;
$data[] = $subdata;
}
$json_data = array(
'draw' => intval($request['draw']),
'recordsTotal' => intval($totalData),
'recordsFiltered' => intval($totalFilter),
'data' => $data
);
echo json_encode($json_data);
我可以看到json输出的行数准确,但没有数据:
{“绘制”:0,“ recordsTotal”:81,“ recordsFiltered”:81,“数据”:[]}
谢谢。