我有两张桌子,一张有帖子,另一张有评论:
posts
-----
ID
user_ID
text
date
comments
--------
ID
post_ID
user_ID
text
date
我想显示每个帖子,对于每个帖子,我想显示相关评论。所以我做了两个查询:
include('bdd.php');
$reponse = $bdd->query('
SELECT posts.ID AS post_ID, posts.user_ID, posts.text, posts.date FROM posts
ORDER BY posts.ID DESC
');
while ($post = $reponse->fetch()){
//displaying a post
$get_comments=$bdd->query('SELECT * FROM comments WHERE post_ID ='.$post['post_ID']);
while($comment = $get_comments->fecth()){
//displaying a comment
echo $comment['text']
}
}
但是代码停止了,只显示没有评论的第一篇文章。