09-26-2017, 10:39 AM
Hi, i would like delete multiple rows using checkbox.
Please, someone can help me? Thanks.
View:
Controller:
Model:
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>
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');
}
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();
}