Scenario: many to many relationships.
table has 2 columns: UserID and UserChoiche
I am storing the user preferences one by one in each row. (Is this the most efficient way?)
Example:
UserID UserChoiche
mark
anna
mark
paul
mark
john
john
mark
In this example mark chose 3 users, and john chose 1 user.
John and Mark have chosen each other and I need php to find this db relationship.
//php mysql query that selects all the choiches of a specified user (in this case mark)
SELECT UserChoiche from exampletable WHERE UserID mark
//find the matches
??
here is my problem: I am looking for the easiest and most efficent way to handle this!
Maybe like this? (It could work but I cannot write a mysql statement, is too complicated for me!)
If Userchoice of previous query (in this case it would return anna paul and john) EQUALS any Userid in the table (in this case john) AND that Userid has a Userchoiche with the value of the UserID from the previous query (in this example 4th row)
then we have a match
//if matches found, then take the UserID and UserChoiche and store them into variables which I will use to make some notifications (there can be many matches, so maybe use an array?)