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

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)