'How to display MySQL table using php and edit it in a web browser

i am using a while loop to display all the data in my MYSQL table. the problem is that its not showing the newest entry. after adding a record it does not show the record in my browser, but it would have been added in the database. it will show after i add another one. i have attached pictures.

enter image description here

enter image description here

Here is my code

  <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>


Solution 1:[1]

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

Advances you to the second row everytime. Remove the first fetch call. Everytime you fetch you advance one row. So for example:

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

would print the third row.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3783243