I actually need to delete multiple rows that are checked via ajax in codeigniter. when i click the delete button it gives me the value of all the selected check box but its not passing all the values to controller and hence only the last checked value is getting deletd please help me..
View Page...The javascript is called when the
<div class="multiple_del" title="Delete"><img src="../../images/minus.png"/></div>
</div>
is clicked
<table border="0" cellpadding="0" style="width:100%;margin:0px auto" cellspacing="0" id="product-table">
<thead>
<tr>
<th class="tbl_hdr sorter-false"><img src="../../images/trash.png" style="padding-left:13px;"/></th><!--Multiple Delete--->
<th class="tbl_hdr">USER ID</th> <!--ID-->
<th class="tbl_hdr">NAME</th> <!--Name-->
<th class="tbl_hdr">EMAIL</th> <!--Email-->
<th class="tbl_hdr">PHONE NUMBER</th> <!--ph number-->
<th class="tbl_hdr sorter-false">STATUS</th> <!--publish/unpublish-->
<th class="tbl_hdr sorter-false" colspan="2">ACTION</th> <!--edit/delte-->
</tr>
</thead>
<tbody>
<?php
$count=1;
foreach($users as $user){
if($count%2==0){?>
<tr class="alternate-row"><?php }?>
<td><input type="checkbox" name="checkboxlist" value="<?php echo $user->id;?>"/></td>
<td><?php echo $user->id;?></td>
<td><?php echo $user->username;?></td>
<td><?php echo $user->email;?></td>
<td><?php echo $user->contact;?></td>
<?php if ($user->status==0)
{?>
<td>
<div align="center">
<a class="status unpublished" value="<?php echo $user->id;?>" title="Unpublished"></a>
</div>
</td>
<?php }
else
{?>
<td>
<div align="center">
<a class="status published" value="<?php echo $user->id;?>" title="Published"></a>
</div>
</td>
<?php }?>
<td>
<a class="editbutton"><span class="edit editbutton" title="Edit"><img src="../../images/edit.png"/></span></a>
<a class="removebutton" onclick="deleteuser('<?php echo $user->id;?>')"><span class="delete removebutton" title="Delete"><img src="../../images/delete.png"/></span></a>
</td>
</tr>
<?php $count++;}?>
</tbody>
</table>
<div>
<div class="multiple_del" title="Delete"><img src="../../images/minus.png"/></div>
</div>
Javascript...
$(document).ready(function(){
$('.multiple_del').click(function(){
var checkValues = $('input[name=checkboxlist]:checked').map(function()
{
return $(this).val();
}).get();
//alert(checkValues);
var url='<?php echo base_url(); ?>index.php/admin/delete_multiple';
$.ajax({
type: 'POST',
url: url,
data: { ids: checkValues },
success:function(data)
{
window.location="<?php echo base_url(); ?>index.php/admin/users";
$( ".msg1" ).text( "Selected Users Deleted..!!");
}
});
});
});
Controller...The ajax url goes to this controller
public function delete_multiple()//Delete Multiple Users
{
$ids=$this->input->post('ids');
$this->admin_model->delete_multiple($ids);
}
Model...
function delete_multiple($ids)//Delete Multiple Users
{
$this->db
->where_in('id', $ids)
->delete('tbl_users');
}