我已經嘗試過了,但是我無法知道我在哪裏做錯了。該表只連續回顯第一行,並沒有回顯其他行。請幫助。使用php創建動態數據庫表db
$run = "
SELECT * FROM staff
";
$runquery = mysqli_query($connection, $run);
$runrow = mysqli_num_rows($runquery);
if($runrow < 1){
echo "<p class='errormsg'>You do not have any Staff</p>";
}
else{
$row = mysqli_fetch_array($runquery);
if($row) {
$surname = $row['surname'];
$lastname = $row['lastname'];
$phone = $row['phone'];
$username = $row['username'];
$role = $row['auth'];
}
foreach ($row as $staff) {
$table .= "
<tr>
<td>$surname</td>
<td>$phone</td>
<td>$username</td>
<td>$role</td>
</tr>
";
}
}
因爲您在循環之前設置變量。 – Noman
不工作。我試過 –
檢查我的答案 – Noman