douzhe1264 2018-05-20 10: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 10:59
    关注

    Change

    while($result -> fetch_assoc()){
    

    To

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

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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部