【发布时间】:2017-06-03 17:27:33
【问题描述】:
我正在为我的学校科目做一个项目。我对如何检查复选框中的数据感到困惑,当我按下提交按钮时,它将循环插入到我的数据库中。我设法显示/提醒正在我的数据表中检查的数据。
这是我的控制器,用于填充我的数据表:
public function getalldocs() {
$listdocs = $this->Admin_model->getdoctors();
$data = array();
foreach ($listdocs as $docs) {
$row = array();
$row[] = $docs->user_fname;
$row[] = $docs->user_mname;
$row[] = $docs->user_lname;
$row[] = '<input name="user_id[]" value="'.$docs->user_id.'" type="checkbox">';
$data[] = $row;
}
$output = array(
"data" => $data,
);
echo json_encode($output);
}
在我看来:
<div class="dataTable_wrapper">
<table id="dataTables-docs" class="table table-striped table-bordered table-hover dataTable dtr-inline" role="grid" style="width: 100%;" width="100%" aria-describedby="dataTables-material">
<thead>
<tr>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
</div><!-- dataTable_wrapper -->
这是我的 javascript 从我的数据表中回显选定的复选框:
function show_docs() {
$("#dataTables-docs").dataTable().fnDestroy();
table = $('#dataTables-docs').DataTable({
"ajax": {
"url": "<?php echo site_url('admin_controls/getalldocs')?>",
"type": "POST",
},
responsive: true,
className: 'select-checkbox',
'bInfo': false,
'paging': false
});
}
$('#dataTables-docs tbody').on('click', 'input[type="checkbox"]', function(e){
var user_id = $(this).val();
alert(user_id);
});
现在,我希望将所有正在检查的内容插入到我的数据库中,如下所示: (myid,selectedfromcheckbox); 这是我从数据库表中截取的屏幕截图:
【问题讨论】:
标签: php mysql codeigniter datatable datatables