您好,我想知道是否可以执行诸如在数据表中选择一行并使用 Controller 中的方法添加“删除”按钮之类的操作。
我的删除按钮是从数据库本身中删除该行并刷新页面。
这是我的 View 包含的内容:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#datatables').DataTable();
});
</script>
<table id= "datatables" class = "table">
<thead>
<tr>
<th> Patient Name </th>
<th> Patient`enter code here` ID </th>
</tr>
</thead>
<tbody class = "list">
<?php foreach ($patients as $patient): ?>
<tr>
<td><?=$patient->first_name ?></td>
<td><?=$patient->patientID ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
(删除按钮) echoanchor('某物/删除', '删除', 'class= "某个类"');
我想做的是:
获取数据表中所选行的 ID,并将其传递到 Controller 中的另一个页面进行处理。
这可能吗?
最佳答案
因为您正在使用 DataTables 插件。定义列时,添加复选框列,如下所示:
{
"data": null,
"defaultContent": "",
'class':'user_chkbox',
"searchable": false,
"render": function ( data, type, full, meta ) {
var checkbox = "<input type='checkbox' name='user_ids[]' value='" + data.id + "' />";
return checkbox ;
}
},
您可以通过访问“user_ids”帖子数据来获取要删除的 ID 列表。
$user_ids = $this->input->post('user_ids');
然后您可以在提交处理函数中:
$this->db->where_in('id',$user_ids);
$this->db->delete('user_table');
关于php - CodeIgniter从涉及mysql数据库的数据表中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32611190/