这个PHP应该返回4行数据.... 行A,行B,行C,行D
$query = $mysqli->query("select codeid,description from codeTable where tableCode='TABLE'");
$json = array();
if($query->num_rows){
while($tblArray[] = $query->fetch_object()){
$json[]=$tblArray;
}
}
echo json_encode($json);
但实际上,json_encode显示了10行数据.... A行, A行,B行, A行,B行,C行, 行A,行B,行C,行D
[[{"codeid":"4","description":"Document Type"}],[{"codeid":"4","description":"Document Type"},{"codeid":"8","description":"Images"}],[{"codeid":"4","description":"Document Type"},{"codeid":"8","description":"Images"},{"codeid":"1","description":"Note Type"}],[{"codeid":"4","description":"Document Type"},{"codeid":"8","description":"Images"},{"codeid":"1","description":"Note Type"},{"codeid":"5","description":"Projects"}]]
有人能告诉我为什么会这样吗?最终目标是将查询返回的四行数据放入javascript数组中。
答案 0 :(得分:1)
// remove [] here, or you are adding the row data to an array, then add to another array.
while($tblArray = $query->fetch_object()){
$json[] = $tblArray;
}