loop through two sql queries php
<p>Hi I have two tables (users &amp; friends) I need to connect to the friend table to bring all the friends for a user id, then connect to the user table and bring the information for that user, using the friend id. I have the code below but this only brings one user.</p>

<p>It needs to count the number of users online.</p>

<pre><code>function online_friends()
{

$ID = ($_SESSION['ID']);
$friend = "SELECT * FROM `friends` WHERE `user_id` = '$ID' AND `accepted` = 'TRUE'";
$result=mysql_query($friend);

    while ($row = mysql_fetch_assoc($result)) 
    {
    $friend_id = $row['friend_id'];
    $get = "SELECT * FROM `users` WHERE `ID` = '$friend_id' AND `online` = 'TRUE'";
    $result_friend=mysql_query($get);
    $count_friends=mysql_num_rows($result_friend);
    }
    return $count_friends;

}
</code></pre>

<p>Thanks
Edit: I have checked these manually by running through phpmyadmin and it brings two or more rows.</p>
