Forum Moderators: coopster
So i have to get information from 2 tables. The "journal_entries" table to see when the latest entries were made, and the "friends" table, so i only return results from people who are your friend.
$result7=mysql_query("SELECT friend_id FROM friends WHERE user_id = '$username'");
//this gets the names of your friends. As you can see, the query is unused so far.
$result8=mysql_query("SELECT journal_id, MAX(entry_timestamp) AS entry_timestamp FROM journal_entries GROUP BY journal_id ORDER BY entry_timestamp DESC LIMIT 0, 5");
//this gets all the latest entries for everybody on the site, not just your friends. To limit the results from $result8 to only those names that turned up from $result7, how would i put that?
Or am i going about this all wrong?
But really it depends on the structure you have.
Let me know if I have been any help.
Habtom
$result7=mysql_query("SELECT friend_id FROM friends WHERE user_id = '$username'");
$friendid = mysql_fetch_row($result7);
$result8=mysql_query("SELECT journal_id, MAX(entry_timestamp) AS entry_timestamp FROM journal_entries WHERE journal_id = '$friendid' GROUP BY journal_id ORDER BY entry_timestamp DESC LIMIT 0, 5");
But it returns no results. Any other ideas?
The friends table has friend_id (the username of your friends) and user_id (your username). It also has pending_id but its not relavent here.
$result7=mysql_query("SELECT friend_id FROM friends WHERE user_id = '$username'");
$f = array();
while ($i = mysql_fetch_array($result7)) {
$f[] = $i['friend_id'];
}
$f1 = $f[0];
$f2 = $f[1];
$f3 = $f[2];
$f4 = $f[3];
$f5 = $f[4];
$result8=mysql_query("SELECT journal_id, MAX(entry_timestamp) AS entry_timestamp FROM journal_entries WHERE journal_id = '$f1' ¦¦ journal_id = '$f2' ¦¦ journal_id = '$f3' ¦¦ journal_id = '$f4' ¦¦ journal_id = '$f5' GROUP BY journal_id ORDER BY entry_timestamp DESC LIMIT 0, 5");
$result8 now returns what i want.