我有两个表,一个与职位和另一个注释:PHP/MySQL的 - 使用一个查询的结果在其他查询中使用
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']
}
}
但代码停止,只显示没有评论的第一篇文章。
:或
$bdd->query();
错字错误更换
$bdd->prepare();
?尝试在第一次之前插入'$ reponse-> execute();'。或用'$ bdd-> query()替换'$ bdd-> prepare();'' –是的,你说得对,当我简化代码时,我忘了它,我刚刚添加它。它不能解决问题。不管怎么说,还是要谢谢你。 – Codophage
我发布它作为答案,接受它。快乐编码 –