Jump to content

mysql query comparing columns


shortysbest

Recommended Posts

I have a table called "friends" and 4 columns called:  id......friend_1......friend_2.......date

 

I want to retrieve all of the friends of the user that is logged in, so if the table looks like:

 

friend_1.........friend_2

3.........................6

6.........................8

12.......................3

 

the result if the users id is 3 would be:

6

12

and if the users id was 6 it would be:

3

8

 

 

the query I have right now partially works, just note sure how to modify it to get the full result I want.

 

$get_friends = mysql_query("SELECT * FROM friends WHERE (friend_1='".$session."' OR friend_2='".$session."')");
while($friends = mysql_fetch_array($get_friends))
{
print $friends['friend_1'];
}

with the code above if you use the table I showed above and assumed that $session = 3, the result is:

3

12

 

but should be:

6

12

 

hopefully that's pretty straight forward, thanks in advanced.

Link to comment
https://forums.phpfreaks.com/topic/231061-mysql-query-comparing-columns/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.