[英]How to display MSQL table using php and edit it in a web browser
我正在使用while循環來顯示我的MYSQL表中的所有數據。 問題是它沒有顯示最新的條目。 添加記錄后,它不會在我的瀏覽器中顯示該記錄,但是它會被添加到數據庫中。 我添加另一個后,它將顯示。 我已附上圖片。
這是我的代碼
<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);
將打印第三行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.