php - 如何使用 php 显示 MySQL 表并在网络浏览器中编辑它

标签 php html mysql

我正在使用一个 while 循环来显示我的 MYSQL 表中的所有数据。问题是它没有显示最新条目。添加记录后,它不会在我的浏览器中显示该记录,但它会被添加到数据库中。 它会在我添加另一个后显示。我附上了照片。

enter image description here

enter image description here

这是我的代码

  <table id="t02" width="100%" border="1px">
                    <tr>
                        <th>Ec Number</th> 
                        <th>Username</th>
                        <th>Email</th>
                        <th>Phone Number</th>
                        <th>Department</th>
                    </tr>
            <?php 

            $sql = "SELECT * FROM lecturer";

            $result = $conn->query($sql);

            $row = $result->fetch_assoc();

            while ($row = $result->fetch_assoc()){
                echo "<tr>";

                echo "<td>".$row['ecnumber']."</td>";
                echo "<td>".$row['username']."</td>";
                echo "<td>".$row['email']."</td>";
                echo "<td>".$row['phonenumb']."</td>";
                echo "<td>".$row['dept']."</td>";

                echo "</tr>";
            }

            ?>


                </table>

最佳答案

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

每次都会将您推进到第二行。删除第一个 fetch 调用。每次您 fetch 都会前进一行。例如:

$row = $result->fetch_assoc();
$row = $result->fetch_assoc();
$row = $result->fetch_assoc();
print_r($row);

将打印第三行。

关于php - 如何使用 php 显示 MySQL 表并在网络浏览器中编辑它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51715303/

相关文章:

java - 截断不正确的 INTEGER 值 : '%' in Java and MySQL

android - 遍历嵌套的 json 对象并将数据保存在 android sqlite 中

php - 如何将可空变量转换为不可空类型?

php - 如何在laravel中写套接字服务器?

javascript - 图像未绘制在 Canvas 上 (HTML5)

javascript - 如何使用 jQuery 变量隐藏 HTML 表格行

javascript - D3.js分层边缘捆绑按组着色

从查询字符串中删除键的 PHP 函数

php - 如何在函数中使用外部变量?

PHP 和 Mysql 特殊字符