This is my statement for me to pull all the data of my users’ friends that they have added:
$q = $dbc -> prepare("SELECT a.* FROM accounts a INNER JOIN friends fr ON (a.id = fr.friend_id) WHERE fr.id = ?");
$q -> execute(array($details['id']));
Now this is basically where the id matches in the friends table, pull the friends id and all the relevant data with it.
I am trying to implement a friends online page as well, how would I also test to see if a column in accounts for the friend_id matches a certain criterion?
This is how I pull all the users that are online…
$online_users = time() - 900;
$q = $dbc -> prepare("SELECT * FROM accounts WHERE last_active > ? && id != ? ORDER BY id");
$q -> execute(array($online_users, $details['id']));
You don’t need to repeat the condition on
a.idsince the join enforces it.