首页 > 解决方案 > 我怎样才能在保留回复的同时移动我的评论?

问题描述

我正在尝试创建一个评论系统,用户可以在其中发表评论,然后其他用户可以回复这些评论。我希望实际的帖子位于页面的左侧,评论位于右侧,这样用户就不必滚动到实际的帖子来阅读评论。我尝试过使用 position: absolute,但这会干扰我的回复系统。有谁知道更简单的方法来做到这一点?

我的代码

while ($commentrow = mysqli_fetch_assoc($commentresult)) {
                        if (mysqli_num_rows($commentresult)==0) {
                            echo '';
                        }
                        else {
                            $commenterid = $commentrow['userid'];
                            $commentersql = "SELECT * FROM users WHERE userid = '$commenterid'";
                            $commenterresult = mysqli_query($conn, $commentersql);
                            while ($commenterrow = mysqli_fetch_assoc($commenterresult)) {

                                echo     '<div class="PostComments">';

                                    if ($commenterrow['profileimg'] == 1) {
                                        $filename = "profilepics/profile".$commenterid."*";
                                        $fileinfo = glob($filename);
                                        $fileext = explode(".", $fileinfo[0]);
                                        $fileactualext = $fileext[1];
                                        echo "<div class='CommentProfilePicture'><img src='profilepics/profile".$commenterid.".".$fileactualext."?".mt_rand()."'></div>";
                                    }
                                    else {
                                        echo "<div class='CommentProfilePicture'><img src='profilepics/noUser.png'></div>";
                                    }

                                echo     "<div class='CommentUserName'>".$commenterrow['userName']."</div>";
                                echo    "<div class='CommenterComment'>".$commentrow['comment']."</div> </div>";
                            }

                            $currentcommentid = $commentrow['commentid'];
                            $replysql = "SELECT * FROM posts WHERE hostid = '$hostid' AND postid = '$postid' AND commentid = '$currentcommentid' AND replyid > 0";
                            $replyresult = mysqli_query($conn, $replysql);
                            while ($replyrow = mysqli_fetch_assoc($replyresult)) {
                                if (mysqli_num_rows($replyresult)==0) {
                                    echo '';
                                }
                                else {
                                    echo '
                                            <div class="PostReplies">
                                                <p>
                                                    '.$replyrow['reply'].'
                                                </p>
                                            </div>
                                    ';
                                }
                            }
                        }
                    }

我的造型

.PostPage {
          width: 60%;
          padding: 10px;
          background-color: #555;
          color: white;
          margin: 0px;
    }
    .PostComments {
          width: 30%;
          background-color: #555;
          padding: 10px;
          border-radius: 4px;
          color: white;
    }
    .PostReplies {
          width: 30%;
          background-color: #555;
          padding: 10px;
          color: white;
    }

如果您有任何问题,我将非常乐意回答。

标签: phphtmlcss

解决方案


在评论和回复上创建一个 div 标签。


推荐阅读