需要帮助来构建这样的表https://datatables.net/examples/data_sources/ajax.html
我在mysql中有近50万行的表。我想通过ajax在jQuery Datatable中加载neary 10k行。我怎么这样格式化?
{
"data": [
[
"Tiger Nixon",
"System Architect",
"Edinburgh",
"5421",
"2011/04/25",
"$320,800"
],
...
[
"Garrett Winters",
"Accountant",
"Tokyo",
"8422",
"2011/07/25",
"$170,750"
]
]
}
来自这个
foreach ($query as $result){
... $result['msgid'], $result['msgdate']...
}
我现在尝试的是
$a = '
{
"data":
[';
foreach($q as $r){
$a.= '[
"'.$r['msgid'].'",
"'.$r['msgdate'].'"
],';
}
$a = rtrim($a,',');
$a.=']
}';
echo $a;
答案 0 :(得分:0)
您可以使用json_encode
功能
答案 1 :(得分:0)
首先我会改变:
$a = '
{
"data":
[';
foreach($q as $r){
$a.= '[
"'.$r['msgid'].'",
"'.$r['msgdate'].'"
],';
}
$a = rtrim($a,',');
$a.=']
}';
echo $a;
要:
echo json_encode(array('data' => $a));
您也可以更改php.ini文件中的max_execution_time
。
也请考虑这种方式:
$a = array();
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_assoc($result)) {
array_push($a, $row );
}