Welcome Guest, Not a member yet? Register   Sign In
Delete multiple rows using checkbox
#1

Hi, i would like delete multiple rows using checkbox.
Please, someone can help me? Thanks.


View:
Code:
<table class="uk-table uk-table-striped">
    <thead>
      <tr>
        <th>Nome</th>
        <th>E-mail</th>
        <th>Sito Web</th>
        <th>Data</th>
        <th>Commento</th>
      </tr>
    </thead>
    <tbody>
      <?php foreach($commenti as $single) : ?>
        <tr>
          <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>
        </tr>
      <?php endforeach; ?>
    </tbody>
  </table>
Controller:

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

 
     $this->load->model('guestbook_model');
 
     $id $this->input->post('ckbdelete');
 
     $this->guestbook_model->DeleteById($id);
 
     // 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>');
 
     redirect('admin/index');

 
 
Model:

PHP Code:
public function DeleteById($id){
 
   //$this->db->delete('guestbook', array('id' => $id));
 
    $this->db->where('id'$id);
 
    $this->db->delete('guestbook');
 
    return $this->db->affected_rows();
 
 
Reply
#2

This
$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){
$this->guestbook_model->DeleteById($i);
}
On the package it said needs Windows 7 or better. So I installed Linux.
Reply
#3

Here is a full script for delete multiple records using checkbox in Codeigniter application, You can follow: https://itsolutionstuff.com/post/how-to-...ample.html
I hope it can help you...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB