我正在尝试从com_comments表中检索特定博客文章的所有评论。但是,我已经对该博客帖子的ID进行了硬编码,并且想知道该怎么做才能仅检索专门链接到用户选择的任何帖子的评论。
// get post with id 1 from database
$post_query_result = mysqli_query($conn, "SELECT * FROM blog_posts
WHERE id=1");
$post = mysqli_fetch_assoc($post_query_result);
// Get all comments from database
$comments_query_result = mysqli_query($conn, "SELECT * FROM
com_comments WHERE post_id=" . $post['id'] . " ORDER BY created_at
DESC");
$comments = mysqli_fetch_all($comments_query_result, MYSQLI_ASSOC);
我希望这些评论仅显示在专门选择的博客文章上。