I can't seem to find what is wrong with my code. I want to be able to delete records which have been checked in a table.
This is my VIEW:
<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>
My ajax function which was called in the view:
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!'
});
}
});
});
}
My Controller:
public function remove_category()
{
$checked = $this->input->post('delete');
$this->category_model->delete_category($checked);
redirect('category/read_category');
}
Model:
function delete_category($id)
{
$this->db->where('id', $id);
$this->db->delete('tblitemcategories');
}
There are no errors returned by firebug. I'm not sure what's wrong and I've tried changing my code based on the other questions of other users which were answered here in stack, but mine still doesn't work. Any help is much appreciated. I'm pretty new to Codeigniter and PHP. Thanks again in advance!
</div>