开发者

PHP MySQL query JOIN HELP

Hey everybody. So, I'm creating this kind of a social network script for a project of mine and i need it to display a news feed similar to facebooks feed, that is, to display your friends posts and your own posts...but with my technique it only displays friends post.

my query is the following:

SELECT 
                * 
            FROM 
                ajee_friends
            JOIN
                ajee_wall
            ON
                ajee_friends.fid = ajee_wall.uid
            WHE开发者_运维问答RE 
                ajee_friends.uid = '$this->uid'


If you want the wall of your friends and your own this can be done (in my opinion more readable as subselect):

SELECT *
  FROM ajee_wall w
 WHERE w.uid IN (SELECT fid FROM ajee_friends WHERE uid = $this->uid)
    OR w.uid = $this->uid


    SELECT *
    FROM ajee_wall w
    WHERE w.uid IN
        ( SELECT fid 
          FROM ajee_friends
          WHERE uid = $this->uid
        )
UNION ALL
    SELECT *
    FROM ajee_wall w
    WHERE w.uid = $this->uid


I think you can use Union all... something like,

SELECT * FROM ajee_friends UNION ALL SELECT * FROM ajee_wall

It'll show all of your post and your friends'. You can make it show just a few lines with limit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜