我試圖檢查一個數組中是否存在一個值,如果存在,它應該從數據庫回顯關於該值的信息。如果數組和數據庫中都存在值
我現在得到的是「空」結果,但我希望在列表中至少得到三個結果,這兩個結果都存在於數組和數據庫中。
這是一個後續代碼var_dump外觀數組的,它不是整個數組,但它仍然看起來是一樣的:$friends = array($friends['data']);
array(1) {
[0]=>
array(680) {
[0]=>
array(2) {
["name"]=>
string(17) "One friends name"
["id"]=>
string(8) "FRIEND_ID"
}
[1]=>
array(2) {
["name"]=>
string(13) "Another friends name"
["id"]=>
string(9) "FRIEND_ID"
}
[2]=>
array(2) {
["name"]=>
string(22) "Another friends name"
["id"]=>
string(9) "FRIEND_ID"
}
的PHP代碼:
<?php
$query_top_list_friends = mysql_query("
SELECT * FROM ".$DBprefix."users
WHERE center_id='" . $personal['center_id'] . "'
ORDER BY workouts DESC LIMIT 10");
$i = 0;
$friends = array($friends['data']);
while ($top_list_friends = mysql_fetch_array($query_top_list_friends))
{
//Below it should only echo if the "fid" in the database and the "id" in the array is equal, then it should echo information based on that id from the database
if($friends[$top_list_friends['fid']])
{
$i++;
echo "<div class='user'>";
echo "<span class='number'>" . $i . "</span>";
echo "<span class='name'>" . $top_list_friends['name'] . "</span>";
echo "<span class='workouts'>" . $top_list_friends['workouts'] . "</span>";
echo "</div>";
}
}
任何想法如何我可以修復這個?
謝謝!它幾乎很好:)但是這裏變量$ query_top_list_friends是空的,你知道可能是什麼問題嗎? – Kim
如果我做一個$ sql_in_values var_dump它顯示我的所有id的數組,包括也存在於數據庫中的id – Kim
嗯,我只是猜測與查詢,嘗試'echo「 SELECT * FROM」。$ DBprefix。「。用戶 WHERE center_id ='「。 $ personal ['center_id']。 「' AND WHERE fid IN(''。implode(',',$ sql_in_values)。'') ORDER BY exerciseouts DESC LIMIT 10」'然後在PHPMyAdmin(或任何你使用的)中運行查詢。我用'fid',但也許這是錯誤的'ID'? – Prisoner