我正在尝试将json响应设为:
{
"draw":1,
"recordsTotal":992,
"recordsFiltered":992,
"data":[
{
"id":"1",
"business_name":"\u05e4\u05e8\u05d9 \u05d4\u05d3\u05de\u05d9\u05d5\u05df ",
"phone":"08-6280-111"
},
{
"id":"4",
"business_name":"\u05e1\u05d5\u05e4\u05e8\u05e4\u05d0\u05e8\u05dd",
"phone":""
},
{
"id":"5",
"business_name":"\u05d0\u05e0\u05d0\u05d1\u05dc \u05d0\u05d9\u05e8\u05d5\u05e2\u05d9\u05dd",
"phone":""
},
{
"id":"6",
"business_name":"\u05e4\u05d5\u05d8\u05d5 \u05de\u05d1\u05d8",
"phone":""
},
{
"id":"7",
"business_name":"\u05d4\u05de\u05e7\u05e1\u05d9\u05e7\u05e0\u05d9 - \u05e4\u05d3\u05dc\u05d5\u05df",
"phone":""
},
{
"id":"8",
"business_name":"\u05d9.\u05e4.\u05d9 \u05d9\u05e2\u05d5\u05e5 \u05d5\u05e0\u05d9\u05d4\u05d5\u05dc - BLACK",
"phone":""
},
{
"id":"9",
"business_name":"\u05d4\u05e4\u05e6\u05ea \u05e8\u05db\u05d1 \u05d3\u05e8\u05d5\u05dd",
"phone":""
},
{
"id":"10",
"business_name":"\u05de\u05d5\u05e1\u05da \u05e2\u05de\u05d9\u05ea",
"phone":""
},
{
"id":"11",
"business_name":"\u05d9.\u05d1. \u05e9\u05e8\u05d5\u05ea\u05d9 \u05e8\u05db\u05d1",
"phone":""
},
{
"id":"12",
"business_name":"\u05d5\u05d9\u05d6'\u05df \u05e0\u05d3\u05dc\u05df",
"phone":""
},
{
"id":"13",
"business_name":"\u05e9\u05d5\u05e4\u05df \u05ea\u05de\u05d9\u05e8 \u05de\u05e1\u05e2\u05d3\u05d5\u05ea",
"phone":""
},
{
"id":"14",
"business_name":"\u05d2\u05dc\u05d9\u05d3\u05d4 \u05d1\u05d0\u05e8 \u05e9\u05d1\u05e2",
"phone":""
},
{
"id":"15",
"business_name":"\u05e7\u05e6\u05d9\u05e8 \u05e9\u05d3\u05d4 - BBB",
"phone":""
},
{
"id":"16",
"business_name":"\u05d0\u05d5\u05e4\u05d9\u05e1 \u05d3\u05d9\u05e4\u05d5",
"phone":""
},
{
"id":"18",
"business_name":"\u05d0\u05dc\u05d5\u05e3 \u05e1\u05e4\u05d5\u05e8\u05d8",
"phone":""
},
{
"id":"19",
"business_name":"\u05d0\u05d1\u05d9 \u05d5\u05d9\u05d9\u05e6\u05de\u05df - \u05de\u05ea\u05d5\u05d5\u05da",
"phone":""
},
{
"id":"20",
"business_name":"\u05d8\u05d9\u05d8\u05e0\u05d9\u05d5\u05dd \u05d3\u05e8\u05da \u05d0\u05d1\u05d9\u05d1",
"phone":""
},
{
"id":"21",
"business_name":"\u05e1\u05e4\u05d9\u05d3\u05e4\u05e8\u05d9\u05e0\u05d8",
"phone":""
},
{
"id":"22",
"business_name":"\u05e7\u05e0\u05d9\u05d5\u05df \u05d4\u05e0\u05d2\u05d1",
"phone":""
},
{
"id":"23",
"business_name":"\u05d1\u05d5\u05e2\u05d5\u05ea",
"phone":""
}
]
}
我尝试将数据推入内部数组,但无法弄清楚如何在数组中添加具有值和更多字段(如id和phone)的字段,例如 business_name:""
。
我正在尝试使用Ajax进行数据表操作,
我的代码:
$stmt = $link->query("SELECT * FROM `deals`");
if ($stmt->rowCount() > 0):
$data['draw'] = 1;
$data['recordsTotal'] = $stmt->rowCount();
$data['recordsFiltered'] = $stmt->rowCount();
$data['data'] = [];
$i = 0;
while ($row = $stmt->fetch()):
/*$i++;
$data['data'][$i]['id'] = $row['id'];
$data['data'][$i]['property_id'] = $row['property_id'];
$data['data'][$i]['agent_id'] = $row['agent_id'];*/
array_push($data['data'],$row['id']);
endwhile;
endif;
echo json_encode($data);
}
希望有人能帮助我,谢谢高级国王!