我有一个显示用户的代码,还有一个用于删除用户的删除按钮。当我删除任何用户时,删除的用户将从用户列表中删除。在上面,我有两个按钮,一个用于创建用户,另一个用于显示所有已删除的用户。当我单击显示所有用户的下表中的“查看已删除的用户”按钮时,如何显示已删除的用户。
下面是代码
<body class="back-color">
<div class="container">
<div class="table-wrapper">
<div class="table-title">
<div class="row">
<div class="col-sm-7">
<h2><b>Manage Users</b></h2>
</div>
<div class="col-sm-3">
<a href="" class="btn btn-primary" data-toggle="modal"><i class="material-icons">info</i> <span>View Deleted Users</span></a>
</div>
<div class="col-sm-2">
<a href="crtusr.php" class="btn btn-success" data-toggle="modal"><i class="material-icons"></i> <span>Add New User</span></a>
</div>
</div>
</div>
<?php
if($no_of_users>1){
echo '<table class="paginated table table-striped table-hover">
<thead>
<tr>
<th></th>
<th>Username</th>
<th>Email</th>
<th>Role</th>
</tr>
</thead>
<tbody>';
while($userdetails = mysqli_fetch_array($user_details, MYSQLI_ASSOC)){
echo' <tr>
<td></td>
<td>'.$userdetails['username'].'</td>
<td>'.$userdetails['email'].'</td>
<td>'.$userdetails['role'].'</td>
<td>
<a href="" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit"></i></a>
<a href="" class="delete" name="delete" data-toggle="modal" Onclick="return ConfirmDelete()"><i class="material-icons" data-toggle="tooltip" title="Delete"></i></a>
</td>
</tr>';
}
echo '</tbody>
</table>';
}
?>
</div>
</div>
</body>
答案 0 :(得分:3)
我认为您需要一个软删除选项
步骤:
现在单击“删除”按钮,即可将is_deleted设为true。
要仅列出未删除的用户,请查询条件表 is_deleted =>否。
要列出已删除的用户,请查询条件为is_deleted => true的表。
您还可以提供硬删除选项,即从表中删除用户。
您应该喜欢
//if retrieving undeleted users from table
$sql = "SELECT * FROM users from is_deleted = 0";
//else retrieving deleted users from table
$sql = "SELECT * FROM users from is_deleted = 1";
//$con holding your database connection details
$user_details= mysqli_query($con,$sql);
while($userdetails = mysqli_fetch_array($user_details, MYSQLI_ASSOC)) {
// $userdetails array contains the data of a user
// iterate it and fill your table accordingly
}
希望这行得通。