Jump to content

finding mutual friends and selecting information from separate tables MYSQL


shortysbest

Recommended Posts

I am trying to make a filter to show posts from mutual friends between you and the persons profile you're on, I have somewhat of an idea on how to write the mysql query (it needs to be just one query, not two(which would be the easy way of doing it)).

 

the "friends" table has:

"friend_1" and "friend_2"

 

and the "posts" table:

"to_id" and "from_id"

 

The PHP variables would be:

"$session" and "$id"

id would be the users Id of the profile you're on.

 

Thanks, any help would be appreciated.

 

Needs to be just one? Well that depends on how your data is structured and stored. But you could look into JOIN, INNER JOIN, LEFT JOIN.. to query multiple tables. But again in the end it depends on how your storing your data in your DB. You may have to query once for results, have PHP break down the results and then query again for the results of potential match. Again I dont know how your storing your data, and your know giving anyone here much to work with in that factor. No Database is created equally, unless your using a premade system, Wordpress or something to the effect there of, and even then.

 

Also this is a mySQL issue and not a PHP issue. Wish I could be a bit more helpful but, theres just not much to work with.

 

I could say SELECT * FROM jupiter WHERE mars LIKE '%saturn%' and say it applies to what your doing as it makes just as much sense to what your originally posting for code.

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.