Welcome Guest, Not a member yet? Register   Sign In
Updating several rows of db table with one post.
#1

[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.




Theme © iAndrew 2016 - Forum software by © MyBB