dtziv24262 2017-02-03 10:53
浏览 61
已采纳

php迭代通过mysql不显示最近的条目

                $query = "SELECT * FROM `reportlog` WHERE `entity` = '$ent'";
            mysqli_query($db, $query) or die('Error querying database.');

This code does not show the first entry when there is only one entry and then shows the fist but not the second, then 1 2 but not 3 and so on. Basically it dose not ever show the most recent entry. I have no idea why. Please help me

              $result = mysqli_query($db, $query);
            $row = mysqli_fetch_array($result);

       echo "user \t date \t                   note 
";
             while ($row = mysqli_fetch_array($result)) {
             echo $row['user'] . " \t " . $row['date'] . " \t " .  $row['note']. " 
";
            }
  • 写回答

1条回答 默认 最新

  • duandongjin5647 2017-02-03 11:11
    关注

    Remove the first:

    $row = mysqli_fetch_array($result);
    

    This is fetching the first row and removing it from the result set, so your mysqli_fetch_array() in the while loop is starting from the second row.

    FYI... If you change your query to only get columns you want:

    SELECT `user`, `date`, `note` FROM `reportlog` WHERE `entity` = '$ent'
    

    Then you can just do:

    echo implode(" \t ", $row) . " 
    ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?