douzhe1264 2018-05-20 18:57
浏览 56
已采纳

while循环只重复第一行多次

I am trying to output all the rows of the result of a database query but my while loop keeps repeating only the first row multiple times. It repeats only the first row the total number of times of expected outcome. Please I need help.

$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>
            ";
    }
}
  • 写回答

1条回答 默认 最新

  • dongmao4486 2018-05-20 18:59
    关注

    Change

    while($result -> fetch_assoc()){
    

    To

    while($row = $result -> fetch_assoc()){
    

    Also delete the first $row = ... from line 3.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料