用于获取共同朋友的sql语句 [英] Sql statement to fetch mutual friends
问题描述
我有桌上用户和桌面用户
让我们说当前用户访问其他用户的个人资料,个人资料ID为27
可以说
$ user_id = $ _GET ['id'];
然后我点击链接查看该用户的朋友(27)
所以现在他的朋友们是:
18和33
注意:用户18是当前登录用户
如果当前(18)用户也是用户33的朋友,请问如何查询数据库? ??
表格结构:
I have table friends and table users
Lets says a current user visit another user's profile and the profile id is 27
lets say
$user_id = $_GET['id'];
then I click on a link to view the friends of this user(27)
so now his friends are:
18 and 33
Note: user 18 is the current loggedIn user
Please how can I query database if current(18) user is also friends with user 33??
TABLE STRUCTURE:
id | user_one | user_two | status
1 | 18 | 33 | ok
2 | 33 | 27 | ok
在这种情况下,共同的朋友将是用户33.
请帮助
我的尝试:
SELECT IF(user_one ='$ IsLoggIn'或user_two ='。$ _ GET ['id']。',user_two,user_one)
来自朋友
WHERE((user_one ='$ IsLoggIn'OR'user_two ='。$ _ GET ['id']。')OR(user_two ='$ IsLoggIn'OR user_two ='。$ _ GET ['id'] 。')
In this case the mutual friend will be user 33.
Please help
What I have tried:
SELECT IF(user_one = '$IsLoggIn' OR user_two = '".$_GET['id']."', user_two, user_one)
FROM friends
WHERE ((user_one = '$IsLoggIn' OR user_two = '".$_GET['id']."') OR (user_two ='$IsLoggIn' OR user_two = '".$_GET['id']."')
推荐答案
user_id =
user_id =
_GET ['id'];
然后我点击链接查看该用户的朋友(27)
所以现在他的朋友们是:
18和33
注意:用户18是当前登录用户
如果当前(18)用户也是用户33的朋友,请问如何查询数据库?? ??
< br $>
TAB LE STRUCTURE:
_GET['id'];
then I click on a link to view the friends of this user(27)
so now his friends are:
18 and 33
Note: user 18 is the current loggedIn user
Please how can I query database if current(18) user is also friends with user 33??
TABLE STRUCTURE:
id | user_one | user_two | status
1 | 18 | 33 | ok
2 | 33 | 27 | ok
在这种情况下,共同的朋友将是用户33.
请帮助
我的尝试:
SELECT IF(user_one ='
In this case the mutual friend will be user 33.
Please help
What I have tried:
SELECT IF(user_one = '
IsLoggIn'或user_two ='。
IsLoggIn' OR user_two = '".
这篇关于用于获取共同朋友的sql语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!