【发布时间】:2016-05-24 03:55:18
【问题描述】:
我正在尝试从 2 个表中检索数据并将多行合并到一个 while 循环中
帖子
post_id content
------ -------
1 content1
2 content2
3 content3
4 content4
comments
id post_id content
------ ------ ------
1 1 Wharton university
1 2 Yale University
我写的sql代码
mysqli_query( $connect, "SELECT * FROM `posts`
INNER JOIN comments ON posts.post_id = comments.post_id ORDER BY 1 DESC");
问题我只得到帖子 id 1 和 2。虽然有超过 30 个帖子
我想在单个 while 循环中获取每个帖子的所有帖子和 cmets。
我该怎么做?
【问题讨论】:
-
jquery 在这个问题中的作用是什么?
-
是从两个表中获取所有列数据! ,我必须为每一列命名吗?
-
there are over 30 posts,还有多少个cmets?对于您的情况,IMO 您应该使用left outer join而不是inner join