CodeIgniter Forums
Updating several rows of db table with one post. - 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: Updating several rows of db table with one post. (/showthread.php?tid=2204)



Updating several rows of db table with one post. - El Forum - 07-22-2007

[eluser]millo[/eluser]
Hi,

I apologise as I'm quite new to codeigniter but I'm going to try and explain what I'm trying to do as clearly as possible ...

I've got a lookup table called auth_document with two columns named 'username' and 'document_id'. It's used for assigning documents to users.

In my view page I use a multiple select to to assign various documents to one user. When I post this page however I don't know how to get all the contents to be written into the db. Normally I'm just inserting or updating one row of data but in this case I could be inserting several rows. My form when rendered looks something like this:

<form action="http://test.dev/admin/document_assign" method="post">
<input type="hidden" name="document_id" value="1" />
Assign this document to the following classes:
<select class="size2" type="text" name="username[]" multiple="multiple" size="4">
<option value="user1"><br />classname1</option>
<option value="user2"><br />classname2</option>
<option value="user3"><br />classname3</option>
</select>
&lt;input type="submit" value="submit" /&gt;
&lt;/form&gt;

So when I post this data it will be one document_id and several users. If for example I select all three users to assign this document then I'd need to update 3 rows in the database. Can this insert be carried out using the active record class? Could someone help me out as to how this could be achieved?

Many thanks in advance.