配列に値が存在するかどうかを確認しようとしています。存在する場合は、データベースからその値に関する情報をエコーする必要があります。
私が今得ているのは「null」の結果ですが、配列とデータベースの両方に存在するリストに少なくとも 3 つの結果が得られると予想しています。
これは配列の 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>";
}
}
これを修正する方法はありますか?