我正在尝试检查数组中是否存在一个值,如果存在,它应该从数据库中回显有关该值的信息。
我现在得到的是“空”结果,但我希望在列表中至少得到三个结果,它们同时存在于数组和数据库中。
这是数组的 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>";
}
}
有什么想法可以解决这个问题吗?