需要以表格形式顯示mysql表格中檢索到的數據,但沒有得到我計劃的正確顯示。這是我希望它看起來像 Target display以php表格形式從mysql數據庫以php的形式顯示數據
但是,這是我根據我的代碼是什麼得到 Current display
這是HTML代碼
<div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Department</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$staff_set = find_all_employee();
while ($staff = mysqli_fetch_assoc($staff_set)) {
//display staff first name, last name, department and action (edit and delete links)
?>
<tr>
<td>
<?php
echo $staff["first_name"];
}
?>
</td>
<?php
$staff_set = find_all_employee();
while ($staff = mysqli_fetch_assoc($staff_set)) {
//display staff last name
?>
<td>
<?php
echo $staff["last_name"];
}
?>
</td>
<?php
$staff_set = find_all_employee();
while ($staff = mysqli_fetch_assoc($staff_set)) {
//display staff department
?>
<td>
<?php
echo $staff["department"];
}
?>
</td>
<td>
<a href="edit_admin.php"><span class="glyphicon glyphicon-pencil"> Edit</span></a>
 
<a href=""><span class="glyphicon glyphicon-trash"> Delete</span></a>
</td>
</tr>
</tbody>
</table>
</div>
下面是使用我的功能從我的員工列表中找到所有員工的列表
function find_all_employee() {
global $connection;
$query = "select * from staff";
$staff_set = mysqli_query($connection, $query);
confirm_query($staff_set);
return $staff_set;
}
Is there一個更好的方式來編寫循環並以正確的方式顯示我的數據?我查了類似的線程,但仍然無法掌握。
爲什麼你調用find_all_employee()函數3次? – Stavros