我正在尝试输出数据库查询结果的所有行,但我的while循环只重复多次第一行。它仅重复第一行预期结果的总次数。我需要帮助。
$sql = "SELECT * FROM review WHERE lid = '".$_GET['id']."'";
$result = $conn -> query($sql);
$row = $result -> fetch_assoc();
if (mysqli_num_rows($result) == 0){
echo "<div class='no-comment'>No Comments found!</div>
<button class='btn btn-default btn-lg center-block' data-toggle='modal' data-target='#Review'>Review Lecturer Now!</button>
";
}else{
while($result -> fetch_assoc()){
echo"
<div class='comment'>
<div class='reviewer-name'>".$row['rid']."<span class='review-date'>".$row['reviewDate']."</span><hr>
<p>".$row['review']."</p></div>
</div>
";
}
}
答案 0 :(得分:3)
更改
while($result -> fetch_assoc()){
要
while($row = $result -> fetch_assoc()){
同时从第3行删除第一个$row = ...
。