dtziv24262 2017-02-03 18: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 19: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) . " 
    ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决