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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.