我试图在div中填充数据。哪个工作正常,但是,第一个div数据将重复一次,如附图所示。我无法在代码中看到任何逻辑错误,希望有人能帮助我。
<div class="posts">
<?php
include("dbconn.php");
$sql = "SELECT *
FROM posts p
INNER JOIN users u
ON p.userID=u.userID
INNER JOIN courses c
ON p.courseID=c.courseID;";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
?>
<section class="post">
<header class="post-header"> <img class="post-avatar" height="48" width="48" src="image/common/tilo-avatar.png">
<h2 class="post-title"><?php echo $row["postTitle"]; ?></h2>
<p class="post-meta"> By <a href="#" class="post-author"><?php echo $row["nickname"]; ?></a> under <a class="post-category post-category-design" href="#"><?php echo $row["courseName"]; ?></a> </p>
</header>
<div class="post-description">
<p> <?php echo $row["postContent"]; ?> </p>
</div>
</section>
<?php
}
} else {
echo "no questions yet";
}
?>
</div>