我在while循环中使用两个查询,因此得到两个数组,我想要 将它们合并为单个数组。这是我的代码。请告诉我我错在哪里?
<?php
While ($row = mysql_fetch_assoc($query8)) {
$res1 = mysql_query("select * from tablename where ... ");
$res11 = mysql_fetch_assoc($res);
$res2 = mysql_query("select * from tablename where ... ");
$res22 = mysql_fetch_assoc($res2);
}
total = array_merge($res11, $res22);
$responseJSON = array(
"response" => total
);
header("content - type: application / json");
response = json_encode($responseJSON);
echo response;
答案 0 :(得分:0)
;和$ res22 = [];
$res11[]=mysql_fetch_assoc($res)
$res22[] = mysql_fetch_assoc($res2);
写下这些并尝试。
答案 1 :(得分:0)
要说出你想做什么有点难,我猜是这样的:
$query8 = mysql_query("select * from table name where ...");
$res1 = array();
$res2 = array();
while($row0=mysql_fetch_assoc($query8)) {
$res1[] = $row0;
$row1 = mysql_fetch_assoc($query8)
$res2[] = $row1;
}
$total=array_merge($res1,$res2);
$responseJSON = array("response" => $total);
header("content-type:application/json");
$response = json_encode($responseJSON);
echo $response;