使用搜索关键字查找用户并通过mutial朋友的订单返回结果

时间:2016-02-01 12:52:38

标签: php mysql database mysqli

我正在构建一个我需要高级用户搜索的应用程序,例如高级社交网络搜索......

Table sl_users 
user_id | full_name | etc
Table sl_user_friends
friend_id | user_id_FK | user_friend_id | accept_status

我的查询就像

SELECT * FROM (

SELECT user_id , full_name ,
(SELECT COUNT( * ) 
FROM (

        SELECT CASE WHEN user_id_FK = users.user_id
        THEN user_friend_id
        ELSE user_id_FK
        END AS friendID
        FROM sl_user_friends
        WHERE user_id_FK = users.user_id
        OR user_friend_id = users.user_id
        )a
        JOIN (

        SELECT CASE WHEN user_id_FK =3
        THEN user_friend_id
        ELSE user_id_FK
        END AS friendID
        FROM sl_user_friends
        WHERE user_id_FK =3
        OR user_friend_id =3
        )b ON b.friendID = a.friendID) as mutial_friend

    FROM sl_users

    ) AS users

我想要这样的结果,但这个查询无效。

  

user_id | full_name | mutial_friend      1阿里11      3名男子10      4 xyz 9

     

如果我是用户3和4是我的朋友,那么我也是4的朋友。   这个查询给我一个错误,如

#1054 - Unknown column 'users.user_id' in 'field list' 

1 个答案:

答案 0 :(得分:1)

在数据库中使用以下查询。没有经过测试,但我希望它能为你效劳。

Error: Uncaught error: "expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60