php - 我怎样才能在保留回复的同时移动我的评论?
问题描述
我正在尝试创建一个评论系统,用户可以在其中发表评论,然后其他用户可以回复这些评论。我希望实际的帖子位于页面的左侧,评论位于右侧,这样用户就不必滚动到实际的帖子来阅读评论。我尝试过使用 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;
}
如果您有任何问题,我将非常乐意回答。
解决方案
在评论和回复上创建一个 div 标签。
推荐阅读
- javascript - 当用户在 html 表的文本字段中输入文本时调用哪个事件侦听器
- c++ - 在 C++ 中找到由两个 3 位数字的乘积构成的最大回文数
- python - 如何使用 python 获取 ECS 集群内实例的 IP 地址?
- spring-mvc - 无法使用 initbinder spring 将日期转换为所需的格式
- reactjs - 詹金斯:在没有 Docker 的情况下构建创建反应应用程序
- firebase - 通过云功能处理时,Firestore 时间戳会转换为地图
- java - Java 8 允许在接口内实现静态方法和默认方法,这是否意味着 Java 允许在 Java 8 中实现多重继承?
- basic - 我怎样才能创建这种类型的机器?
- javascript - Vue-Router 未加载组件
- c++ - SPOJ AGGRCOW 解决方案