我試圖生成一個數組,但不知道如何去做。從while循環創建一個ID數組
我目前得到我的數據,像這樣:
$query = mysql_query("SELECT * FROM users WHERE userEmail LIKE '[email protected]'");
$row = mysql_fetch_array($query);
$query1 = mysql_query("SELECT * FROM categories");
while($row1 = mysql_fetch_array($query1)){
$query2 = mysql_query("SELECT * FROM usersettings WHERE userId = ".$row['userId']." AND usersettingCategory".$row1['categoryId']." LIKE 'y'");
$isyes = mysql_num_rows($query2);
if($isyes > 0){
$cat1 = mysql_query("SELECT * FROM shops WHERE shopstateId = 1 AND (categoryId1 = ".$row1['categoryId']." OR categoryId2 = ".$row1['categoryId']." OR categoryId3 = ".$row1['categoryId'].")");
$cat1match = mysql_num_rows($cat1);
if($cat1match > 0){
while($cat1shop = mysql_fetch_array($cat1)){
$cat1msg = mysql_query("SELECT * FROM messages WHERE shopId = ".$cat1shop['shopId']." and messagestateId = 1");
while($cat1msgrow = mysql_fetch_array($cat1msg)){
echo $cat1msgrow['messageContent']." - ".$cat1msgrow['messageCode'];
$cat1img = mysql_query("SELECT shopimagePath FROM shopimages WHERE shopimageId = ".$cat1shop['shopimageId']);
$imgpath = mysql_fetch_array($cat1img);
echo " - ".$imgpath['shopimagePath']."<br/>";
}
}
}
}
}
但是當用戶有一個商店類別自己的喜好挑選所有3這可能會導致重複。我試圖找到一種方法,只是將消息ID取出而不是整個東西,並將其放入數組中,例如:
1,3,5,7,1,3,5,2 ,4,7,8
然後,我可以運行一個單獨的查詢來說讓我所有的消息,其中的ID是在數組中,但我不確定最有建設性的方式來構建這樣一個數組和數組的例子從一個while循環我看到似乎並不是我正在尋找。
有沒有人能把我推向正確的方向?
爲什麼不使用! '內部連接',並且可以顯示錶格的結構.. – Rafee