0
我使用多个SQL查询的数组,然后使用foreach循环运行查询:把多个值到json_encode
foreach($sql as $query) {
$rs=mysql_query($query, $conn);
if(mysql_num_rows($rs) > 0){
while($result=mysql_fetch_assoc($rs)) {
$json_arr["id"] = $result['sequence'];
$json_arr["value"] = $result['company'];
$json_arr["label"] = $result['company'];
array_push($display_json, $json_arr);
}
} else {
$json_arr["id"] = "#";
$json_arr["value"] = "";
$json_arr["label"] = "No Result Found!";
array_push($display_json, $json_arr);
}
}
然后我需要使用json_encode
并打印结果,如:
$jsonWrite = json_encode($display_json); //encode that search data
print $jsonWrite;
我该如何为所有查询结果做一个json_encode
?
将所有数组合并在一起,json对其进行编码。 – 2014-12-07 21:43:01
我如何合并数组? – user2710234 2014-12-07 21:44:41
你有的代码应该可以正常工作。你得到什么,期望的结果是什么? – redelschaap 2014-12-07 21:44:46