CodeIgniter Forums
CRUD and multiple updating - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CRUD and multiple updating (/showthread.php?tid=37306)



CRUD and multiple updating - El Forum - 01-05-2011

[eluser]Wonder Woman[/eluser]
Hi,

I am wanting to create a CRUD admin section and I have the basic elements already set up - although I want to be able to set records so for example you could set a stored member's account as active or inactive by using a checkbox and doing a multiple update. Is this possible? If so, could you point me in the right direction, thanks.


CRUD and multiple updating - El Forum - 01-05-2011

[eluser]Cristian Gilè[/eluser]
Wonder Woman, it sounds like your prevoius post (http://ellislab.com/forums/viewthread/176677/). I can't see much difference.


CRUD and multiple updating - El Forum - 01-05-2011

[eluser]Wonder Woman[/eluser]
Hey Cristian Gilè,

That's because it is in a way, I realised that I need to be able to update all of the entries where the checkbox has returned false so if the entry is true then set the database to 1 if empty set the entry to 0. Any ideas? Thanks.


CRUD and multiple updating - El Forum - 01-05-2011

[eluser]Cristian Gilè[/eluser]
I hope I understood what you mean. Here my solution.

After submit the form follow these steps:

1. update your table and set to 0 all the entries
2. update your table and set to 1 only the entries you have in the post var (the checkbox array)


CRUD and multiple updating - El Forum - 01-05-2011

[eluser]Wonder Woman[/eluser]
That's what I thought but I'm paginating my results so I can't do that because I will be setting all of the other results to 0 on the other pages. 8-/


CRUD and multiple updating - El Forum - 01-05-2011

[eluser]Cristian Gilè[/eluser]
If you use pagination you can pass to the model limit and offset and select IDs of the entries you need to update

Code:
$this->db->select('id');
$this->db->limit($limit,$offset);
$query = $this->db->get('your_table');

Now, with the IDs list, you can use the above approach to update the entries.