0

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>

1 Answer 1

4
$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.

Sign up to request clarification or add additional context in comments.

4 Comments

how do i do that i am new on stack overflow
There should be a check mark next to the vote mark, here's a link that shows details meta.stackexchange.com/questions/5234/…
i just did Thanks
how do i delete or edit directly that record without going to the phpmyadmin database?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.