需要以表格形式显示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