[英]How to count mutual friends between two users and list them in PHP
I know I am not asking a new question but the problem is that I am not getting the things right... Please help me... 我知道我不是在问一个新问题,但问题是我没有把事情做好...请帮助我...
I have the following tables: 我有以下表格:
users(user_id, full_name, course etc.)
friends(user_id (sender), friend_id (receiver), status)
status decides the relationship, if status=1 it means the request is pending while status=2 means the sender and receiver are friends). status决定关系,如果status = 1,则表示请求待处理,而status = 2,则表示发送方和接收方是朋友。
I just want to count the MUTUAL friends between the current logged-in user and the other user (whom the current logged-in user visits the profile). 我只想计算当前登录用户和另一个用户(当前登录用户访问配置文件的用户)之间的MUTUAL朋友。
And also, I want to list them separately. 而且,我想单独列出它们。
SELECT * FROM
( /* Dervived table for friends of userid 1 */
SELECT * FROM friends where user_id=1) fsof1
JOIN
( /* Dervived table for friends of userid 2 */
SELECT * FROM friends where user_id=2) fsof2
ON fsof1.friend_id = fsof2.friend_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.