Welcome Guest, Not a member yet? Register   Sign In
CRUD - Multiple Delete
#1

[eluser]Kemik[/eluser]
Hello,

I'm improving the backend for CI Base and want to add checkboxes next to different areas (e.g. news) and then a delete button.

What's the best method? I was thinking of adding the checkbox in to the foreach loop which lists each news article. However, how would I create the statement from the inputs?

I've never worked with looped inputs (e.g. for multiple input boxes in an upload form, optional fields, etc) so I'm unsure how to lay it out.

I'm not looking for full code, just a quick pseudo code or explanation.

Thanks.
#2

[eluser]Seppo[/eluser]
Well, to create the checkboxes you can
Code:
foreach ($news as $n)
{
    echo '<input type="checkbox" name="delete[]" value="' . $n->id . '" />';
    echo $n->title;
    echo '<br />';
}

To recover the post data, you just need to

Code:
$delete = $this->input->post('delete'); // here we have an array with the ids

And then to delete it you can use the AR method where_in
Code:
$this->db->where_in('id', $delete);
$this->db->delete('news');
#3

[eluser]Kemik[/eluser]
Thanks. I've never seen an array used in the name before.




Theme © iAndrew 2016 - Forum software by © MyBB