Forums

Multiplier db save seperate rows

flyboeing 08 Sep, 2015
Hello all,

I have a problem with saving the data from the multiplier to the database. I used the demo-multiplier form to create my form and used this forum and FAQ to create the database save. In the last part of the multiplier FAQ it says you need to have two database save, with an unique id. I'm not getting this part.

This is how I set up my form and database save:

This is an overview with all the elements I use in my form.
[attachment=0]1_form elements.png[/attachment]

As you can see, I have a dropdown menu where you can select an airline. I used the following settings for this dropdown menu.
[attachment=0]1_form elements.png[/attachment]

For the multiplier I also have a dropdown menu where people can select an aircraft. Here is a screenshot with the settings I use.
[attachment=2]3_multiplier drop down.png[/attachment]

After adding all the elements to my form I went to the Setup tab. This is what is looks like:
[attachment=3]4_Setup.png[/attachment]

As you can see I have two DB Save. The first one saves the airline_id to the database, the second one saves the multiplier to the database.
[attachment=4]5_First db save airline id.png[/attachment]

This is the second one:
[attachment=5]6_Second db save multiplier.png[/attachment]

Now I go to my website and test the form. I choose an airline from the menu and select which aircraft are in her fleet. Then I click the submit button to save to the data to the database. I added a debugger so I can see what it says....
[attachment=6]7_debugger.png[/attachment]
[attachment=7]8_db save query.png[/attachment]

The data is submitted to the database, however, the airline_id is stored seperate row, and each option of the multiplier also in a seperate row. When I take a look in my mysql database I see the following:
[attachment=8]9_mysql.png[/attachment]

So my question is, how can i put the airline_id is all the rows that are inserted (instead of NULL)?

Hope someone can help me with this!

Regards,
Ruud
GreyHead 08 Sep, 2015
Answer
Hi flyboeing,

The simplest way is probably with a Custom Code action before the second DB Save:
<?php
foreach ( $form->data['data'] as $k => $v ) {
  $form->data['data'][$k]['airline_id'] = $form->data['airline']['airline_id'];
}
?>

Bob
flyboeing 08 Sep, 2015
Thanks Bob! This works very well!
This topic is locked and no more replies can be posted.