如何将postid的评论与postid的帖子联系起来?

问题描述 投票:0回答:1

这是一场真正的斗争。我一直在尝试调试1小时的大部分时间,但我找不到任何解决方案。我正在建立一个与博客文章相关的评论系统。当您发表评论时,您将返回到同一帖子。帖子页面基于postid动态填充。使用相同的postid添加注释,以便仅填充相关帖子。我查询评论的查询是错误的,但我不明白。

Warning
: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given 
in C:\xampp\htdocs\prog1\comments.php on line 31

码:

<?php
require("connect.php");
$postid = $_GET['id'];

if(isset($_POST['postcomment'])){
    $comment = $_POST['comment'];
    $author = $_SESSION['username'];
    $commentQuery = mysqli_query($conn, "INSERT INTO comments (com_content, com_timestamp, com_author, com_postid) VALUES ('$comment', now(), '$author', '$postid')");
    if($commentQuery){
        header('Location: postpage.php?id='.$postid);  
    }


}
?>

<div class="comments-separator">
</div>
<div class="flex-enable comments-wrapper flex-column">
<span class="comment-header">Comments</span>
    <div class="comment-new-wrapper">
        <form class="flex-enable flex-column" method="POST">
            <textarea class="blog-input-text comment-entry" cols="40" rows="3" name="comment"></textarea>
            <input class="comment-button small-white-subtitle" type="submit" name="postcomment" value="Post Comment">
        </form>
    </div>
</div>
<?php
    $summonComm = "SELECT * FROM comments WHERE com_postid='".$postid."' ORDER BY id DESC";
    $resultComm = mysqli_query($conn, $summonComm);
    while ($row = mysqli_fetch_array($resultComm)){
        $comment= $row['com_content'];
        $timestamp= $row['timestamp'];
        $author= $row['com_author'];
    ?>
    <span class="blog-timestamp"><?php echo $timestamp; ?> • Written by <a href="<?php echo $author; ?>.php"><?php echo $author; ?></a></span>
    <span class="blog-entry"><?php echo $comment; ?></span>
    </div>
<?php
}
?>  
php post get
1个回答
0
投票

ORDER BY id DESC不起作用,因为我的db字段被称为“com_postid”。 $timestamp = $row['timestamp']不起作用,因为我的db字段被称为“com_timestamp”。

© www.soinside.com 2019 - 2024. All rights reserved.