所以我正在创建一个Web应用程序,其中管理员可以删除和停用用户帐户。我检索了我的数据库中的帐户,并将它们放在一个HTML表格中,其中包含相应的&#34;删除&#34;和&#34;停用&#34;使用foreach循环的按钮。但是,我很难弄清楚如何按行删除或更新这些记录。目前,我只尝试对停用功能进行编码,这基本上只是更新我的&#34; isActive&#34;数据库中的列来自&#34; 1&#34; (有效)到&#34; 0&#34; (停用)。将<a href="<?php echo base_url()."admin_accounts/acc_deactivate?id=".$row->userid ?>">
置于模态中是否也是正确的?谢谢!
模态 - view_adminaccounts.php:
<?php foreach($users as $row): ?>
<div class="modal fade" id="delete-modal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="signin">
<div class="modal-body text-center">
<p> Are you sure you want to remove this user from the system? </p><br>
<button type="submit" class="btn btn-custom-1">Yes</button>
<button type="button" class="btn btn-custom" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="deactivate-modal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="signin">
<div class="modal-body text-center">
<p> Are you sure you want to deactivate this user from the system? </p><br>
<a href="<?php echo base_url()."admin_accounts/acc_deactivate?id=".$row->userid ?>"><button type="submit" class="btn btn-custom-1">Yes</button></a>
<button type="button" class="btn btn-custom" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
表 - view_adminaccounts.php:
<table class="table table-hover" id="tracking-table">
<tr>
<th><br>First Name</th>
<th><br>Last Name</th>
<th><br>User ID</th>
<th><br>Address</th>
<th><br>E-mail Address</th>
<th><br>Contact Number</th>
<th><br>Action</th>
</tr>
<?php foreach($users as $row): ?>
<tr>
<td><?php echo $row->firstname; ?></td>
<td><?php echo $row->lastname; ?></td>
<td><?php echo $row->userid; ?></td>
<td><?php echo $row->address; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php echo $row->contactnum; ?></td>
<td class="action-button">
<a href="admin-accounts-edit.html"><button type="button" class="btn btn-custom-2">Edit</button></a>
<button type="button" class="btn btn-custom-3" data-toggle="modal" data-target="#delete-modal"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete </button>
<button type="button" class="btn btn-custom-4" data-toggle="modal" data-target="#deactivate-modal"> Deactivate </button>
</td>
<?php endforeach; ?>
</tr>
</table>
控制器:admin_accounts.php
function acc_deactivate()
{
if(isset($_GET['userid']))
{
$id=$_GET['userid'];
$this->load->model('model_accounts');
$this->model_accounts->deactivate($id);
redirect('admin_accounts');
}
}
型号:model_accounts.php
function deactivate()
{
$id=$_GET['userid'];
$this->db->set('0', $isActive);
$this->db->where('userid', $id);
$this->db->update('accounts');
}