场景:多对多的关系.
表有2列:UserID和UserChoiche
我在每行中逐个存储用户首选项.(这是最有效的方式吗?)
例:
UserID UserChoiche
Run Code Online (Sandbox Code Playgroud)
mark anna
mark paul
mark john
john mark
在这个例子中,mark选择了3个用户,john选择了1个用户.
John和Mark选择了对方,我需要php才能找到这个db关系.
// php mysql查询,选择指定用户的所有选择(在本例中为mark)
SELECT UserChoiche from exampletable WHERE UserID mark
//找到比赛
??
这是我的问题:我正在寻找最简单,最有效的方法来处理这个问题!
也许是这样的?(它可以工作,但我不能写一个mysql语句,对我来说太复杂了!)
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)
然后我们有一个匹配
//如果找到了匹配项,那么请使用UserID和UserChoiche并将它们存储到我将用于进行一些通知的变量中(可能有很多匹配,所以可能使用数组?)
SELECT t1.UserID, t2.UserID
FROM table t1, table t2
WHERE t1.UserID = t2.UserChoiche
AND t2.UserID = t1.UserChoiche
Run Code Online (Sandbox Code Playgroud)
这应该吐出两个相互选择的人.我们基本上是为了找到相互关系而加入桌子