PHP MySQL 查询 JOIN HELP

发布于 2024-11-09 07:43:14 字数 395 浏览 0 评论 0原文

嘿大家。所以,我正在为我的一个项目创建这种社交网络脚本,我需要它来显示类似于 Facebook 提要的新闻提要,即显示您朋友的帖子和您自己的帖子......但是用我的技术它只显示朋友的帖子。

我的查询如下:

SELECT 
                * 
            FROM 
                ajee_friends
            JOIN
                ajee_wall
            ON
                ajee_friends.fid = ajee_wall.uid
            WHERE 
                ajee_friends.uid = '$this->uid'

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
            WHERE 
                ajee_friends.uid = '$this->uid'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

感情废物 2024-11-16 07:43:14

如果你想要你的朋友和你自己的墙,可以这样做(在我看来,作为子选择更具可读性):

SELECT *
  FROM ajee_wall w
 WHERE w.uid IN (SELECT fid FROM ajee_friends WHERE uid = $this->uid)
    OR w.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
小清晰的声音 2024-11-16 07:43:14
    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
    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
亽野灬性zι浪 2024-11-16 07:43:14

我认为你可以使用 Union all...
例如,

SELECT * FROM ajee_friends UNION ALL SELECT * FROM ajee_wall

它会显示您和您朋友的所有帖子。您可以让它只显示几行,但有限制。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文