Small social network MySQL help

TreyChristopher

New Member
Jun 22, 2012
7
0
I'm creating a small Twitter-type script for a friend of mine and I can't quite figure out how to get it to only get updates from only your friends. I don't want to use something in the code to grab loads of statuses, then if user is friend etc.. because it would throw an odd amount of updates and might not get any at all..

I have a status table, users table, and a friendships table with 2 columns (friend1 and friend2). So is there any way to tell the MySQL query, "Only get statuses if friend2 exists"
 

Xerses

Member
Dec 29, 2012
30
4
PHP:
$friendcheck = mysql_query("SELECT friend2 FROM friendtable WHERE friend1 = '" . $username . "';");
 
if(mysql_num_rows($friendcheck) > 0) {
       
      mysql_query("SELECT status FROM statustable WHERE username = '" . $username . "';");
       
}

If thats what you mean.
 

TreyChristopher

New Member
Jun 22, 2012
7
0
PHP:
$friendcheck = mysql_query("SELECT friend2 FROM friendtable WHERE friend1 = '" . $username . "';");
 
if(mysql_num_rows($friendcheck) > 0) {
     
      mysql_query("SELECT status FROM statustable WHERE username = '" . $username . "';");
     
}

If thats what you mean.
Not exactly what I mean.. I'm trying to make a "news feed" type page for the homepage that will grab statuses from the status table ONLY if the person is friends with them.. but I want the users to be able to have hundreds of friends, so it wouldn't exactly work to say, "SELECT * FROM statuses WHERE user = '1', '2', '3', '4'...'100'" because it would most likely overload the table, wouldn't it?
 

Users who are viewing this thread

Top