PHP: SELECT and filtering in 2 tables at once
<p>I would like to make a list to show the user´s friends, that are online.</p>

<pre><code>users
id | firstname | lastname | last_access

users_friends
uID | bID | type | accepted 
</code></pre>

<p>That is how my tabels look like.</p>

<p>Firstly I have the user´s id in $USER. </p>

<p>The $USER´s id is stored in a row, in users_friends, at column "uID". bID is the id of the friend.</p>

<p>I also need to check for accepted, if it's 1, else the user is "waiting" and havnt been accepted by the friend yet.</p>

<p>type should also be checked for "friend" as Im having other types there too.</p>

<p>To check whether they are online or not: last_access containing an unix timestamp.</p>

<p>500 seconds since last access, is what I call "online" in the community.</p>

<p>Now that is all you would need to know. I tried building the query myself and came out with this:</p>

<pre><code>    $query = mysql_query("
       SELECT *
        FROM users u, users_friends uf
        WHERE 
            u.last_access &gt; UNIX_TIMESTAMP()-500 
            AND 
              uf.uID = '$USER' 
            AND
            uf.type = 'friend'
                 AND 
                 uf.accepted = '1'
");
</code></pre>

<p>Now i would like to echo the firstname and lastname (from users) of the online friends.</p>

<p>I tried do a while()</p>

<pre><code>while($get = mysql_fetch_array($query)){
echo $get["bID"]."&lt;br&gt;";
   echo $get["firstname"]."&lt;br&gt;";
}
</code></pre>

<p>I am getting my own user´s name($USER) displayed. But the echo bID is the right id´s for my friends, although it shows all (not filtering out the ones who are online).</p>

<p>How can I do this right, what am I missing?</p>
