Friend of a friend in PHP/MySQL?

前端 未结 5 1285
醉话见心
醉话见心 2020-12-04 20:52

I have a social network similar to myspace/facebook. In my code you are either a person\'s friend or not a friend, so I show all actions from people you are friends with (in

5条回答
  •  臣服心动
    2020-12-04 21:13

    This should pull out all the user's friend's posts.

    SELECT * FROM posts WHERE uid IN (SELECT friend_uid FROM friends WHERE uid=1) ORDER BY post_id DESC

    This should pull out all posts that are your friend's friend's.

    SELECT * FROM posts WHERE uid IN (SELECT friend_uid FROM friends WHERE uid IN (SELECT friend_uid FROM friends WHERE uid=1)) ORDER BY post_id DESC

提交回复
热议问题