CodeIgniter Forums
dealing with checkbox - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: dealing with checkbox (/showthread.php?tid=23867)



dealing with checkbox - El Forum - 10-24-2009

[eluser]basty_dread[/eluser]
How can I delete the checked items from the table to my database using codeigniter. any idea about it? Please post and help me. I am new in codeigniter. Thank you.


dealing with checkbox - El Forum - 10-24-2009

[eluser]überfuzz[/eluser]
Do you have a single checkbox or multiple?

An example of how you can do it.
Code:
function erase()
    {
        $this->load->model('model_that_can_erase'); //make a model that erases rows in the database.
            $array = $this->input->post('erase'); //have a checkbox name="erase[]"
            foreach ($array AS $key => $value)
            {
                $this->model_that_can_erase->erase($key); //one function takes key-ids and erases the row. See to it that you get the right id to each chebox.
            }
        }
        
     }



dealing with checkbox - El Forum - 10-24-2009

[eluser]basty_dread[/eluser]
i have many checkbox. it is on a form. usually the checkbox is created using a loop. and the data on the table is load from the database. . thank you for posting uberfuzz.


dealing with checkbox - El Forum - 10-24-2009

[eluser]überfuzz[/eluser]
[quote author="basty_dread" date="1256393785"]i have many checkbox. it is on a form. usually the checkbox is created using a loop. and the data on the table is load from the database. . thank you for posting uberfuzz.[/quote]
Then you could use the form library in your view-file.

Code:
<?php foreach ($data_array AS $keys => $value): ?>
<p>&lt;?php echo form_radio('erase['.$keys.']','erase'); ?&gt;</p>
&lt;?php endforeach; ?&gt;

Edit, you might wanna echo the name of the checkbox.