CodeIgniter Forums

Full Version: Delete multiple rows using checkbox
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, i would like delete multiple rows using checkbox.
Please, someone can help me? Thanks.

<table class="uk-table uk-table-striped">
        <th>Sito Web</th>
      <?php foreach($commenti as $single) : ?>
          <td><input class="uk-checkbox" type="checkbox" name="ckbdelete[]" value="<?php echo $single->id; ?>"><?php echo $single->id; ?></td>
          <td><?php echo $single->name; ?></td>
          <td><?php echo $single->email; ?></td>
          <td><?php echo $single->website; ?></td>
          <td><?php echo date('d m Y h:m', strtotime($single->time_insert)); ?></td>
          <td><?php echo $single->comment; ?></td>
      <?php endforeach; ?>

PHP Code:
public function delete()
     // elimina elemento

     $id $this->input->post('ckbdelete');
     // redirect
     $this->session->set_flashdata('result''<div class="uk-alert-success uk-text-center" uk-alert><a class="uk-alert-close" uk-close></a> Elemento eliminato correttamente!</div>');


PHP Code:
public function DeleteById($id){
   //$this->db->delete('guestbook', array('id' => $id));
    return $this->db->affected_rows();
$id = $this->input->post('ckbdelete');

return an array of ids. you need to loop through the ids and delete each one.

something like this
foreach ($id as $i){
Here is a full script for delete multiple records using checkbox in Codeigniter application, You can follow:
I hope it can help you...