我的問題是,我有一個SQL查詢填充數組,並希望將數組合併到一個新的數組中,其中查詢的ID不是重複的,我試過了merge_array和當我通過URL執行函數時,它不顯示數組中的內容我只是得到ARRAY.Have也試圖將數組連接到另一個數組並獲得相同的結果,再次我的問題是如何加入數組並正確顯示。PHP將數組連接到數組上sql查詢的結果
$rows[0] = array("181", "a","g"); //Results from previous query
$rows[1] = array("181","j","L")
$rows[2] = array("181","p");
$rows[3] = array("182","k");
$rows[4] = array("183","l");
$rows[5] = array("183","p");
$id =0;
$commentsH = "";
while($row=mysql_fetch_array($query_comments)){
If($id == $image){ //image id is the first element in array.
$comments[] =$row;
$commentsH = $comments.",".$commentsH[$i];
}
else{
$id = $image;
$i = $i +1;
}
}
$result = array();
$result["result"] = 500;
$result["message"] = "Database Read Successfully";
$result["comments"] =$commentsH;
echo json_encode($result);
exit;
EXPECTED OUTPUT
$commentsH[0] = array("181", "a","g","j","L","p");
$commentsH[1] = array("182","k");
$commentsH[2] = array("183","l","p");
那麼...聲明'$ image'在哪裏?您在每次迭代和代碼中覆蓋'$ commentSH','$ commentsH'不是您的_expected output_中顯示的數組,'$ commentsH = $ comments。「,」。$ commentsH [$我];'沒有任何意義.. – dbf 2013-04-28 10:02:35
..有什麼你需要知道關於使用[mysql函數](http://php.net/manual/en/function.mysql-query.php ) – dbf 2013-04-28 10:07:51
$ image是一個查詢的結果,我沒有在上面認爲這很明顯,$ commentsH = $ comments。「,」。comments [$ i]在兩個數組之間用「,」連接數組如果陳述是真的,在其他語言C和Java中很常見。 – Freddy 2013-04-28 10:13:32