简体   繁体   English

PHP通过mysql迭代访问最新的条目

[英]php iterate through mysql dosent show most recent entry

                $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. 当只有一个条目时,此代码不显示第一个条目,然后显示拳头而不显示第二个,然后显示1 2而不显示3,依此类推。 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 \n";
             while ($row = mysqli_fetch_array($result)) {
             echo $row['user'] . " \t " . $row['date'] . " \t " .  $row['note']. " \n";
            }

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. 这是在提取第一行并将其从结果集中删除,因此while循环中的mysqli_fetch_array()从第二行开始。

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) . " \n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM