我似乎无法找到我的代码有什么问题。我希望能够删除已在表格中检查过的记录。
这是我的观点:
<table id="table" name="table" class="table table-bordered table-condensed table-striped table-primary table-vertical-center checkboxs">
<thead>
<tr>
<th style="width: 1%;" class="uniformjs"><input type="checkbox" /></th>
<th class="center">Item Category</th>
<th class="center" style="width: 90px;">Actions</th>
</tr>
</thead>
<?php foreach($categorycontent->result() as $row): ?>
<tr>
<th style="width: 1%;" class="uniformjs"><input type="checkbox" name="delete[]" value="<?php echo $row->id; ?>"/></th>
<td class="center"><?php echo $row->category_name; ?></td>
<td class="center">
<a href="#" class="btn-action glyphicons pencil btn-success" title="Edit" onClick="popedit('<?php echo $row->id; ?>', '<?php echo base_url(); ?>category/update_category/', 'category')"><i></i></a>
</td>
</tr>
<?php endforeach; ?>
</table>
<script type="text/javascript">
$(function()
{
popadd("#newcategory", "<?php echo base_url(); ?>category/create_category/", 'category');
popdeletechecked("#deletecategory", "Deleting this record/s will delete all linked information.</br>Are you sure you want to delete it?", "<?php echo base_url(); ?>category/remove_category/");
});
</script>
我在视图中调用的ajax函数:
function popdeletechecked(buttonid, msg, url)
{
$(buttonid).click(function(){
bootbox.confirm(msg,'No', 'Yes', function(result) {
if(result) {
$.ajax({
url : url,
type : 'POST',
success : function(){
window.location = url;
}
});
}
else {
$.gritter.add({// Doesn't work on page reload
title: 'Deleting Cancelled!'
});
}
});
});
}
我的控制器:
public function remove_category()
{
$checked = $this->input->post('delete');
$this->category_model->delete_category($checked);
redirect('category/read_category');
}
型号:
function delete_category($id)
{
$this->db->where('id', $id);
$this->db->delete('tblitemcategories');
}
萤火虫没有返回任何错误。我不确定是什么问题,我已经尝试根据其他用户的其他问题更改我的代码,这些问题在堆栈中得到了解答,但我的代码仍然不起作用。任何帮助深表感谢。我是Codeigniter和PHP的新手。提前再次感谢!
答案 0 :(得分:0)
您应该使用foreach
循环删除。在Controller
:
public function remove_category()
{
$checked = $this->input->post('delete');
foreach($checked as $val){
$this->category_model->delete_category($val);
}
redirect('category/read_category');
}