Inserting into multiple tables with arrays |
[eluser]Loquela[/eluser]
Hi there I have two tables that I need to INSERT and UPDATE with data from a form. My problem here is dealing with Arrays, which I struggle to get my around. THE TABLES: Code: Table Topics: THE FORM VIEW (form_view.php): Code: <form action="submit_form.php"> CONTROLLER (submit_form.php): Code: function submit_form() Code: THE MODEL: I want the model function to insert the form data into 2 tables above. The topics table gets inserted/updated with the topic_id and topic_name (not subject_id). The topic2subject table should have a new row inserted for each selected option in the form and get the topic_id and subject_id. Any help with this greatly appreciated. Thanks in advance. L.
[eluser]sihijau[/eluser]
use insert table in foreach of course take a look this article http://codeigniter.com/wiki/Inserting_Mu...o_a_Table/
[eluser]Krzemo[/eluser]
1. Start new transaction 2. Insert data into 1st table 3. Get last insert id 4. Insert data into 2nd table using last insert id from point above 5. Close transaction 6. Return transaction status or anything you might need from this model function Voila
[eluser]WanWizard[/eluser]
Don't forget to use a database that is capable of using transactons, otherwise this does nothing. |
Welcome Guest, Not a member yet? Register Sign In |