Forums

Adding the five records to a database table at once using one Save Data action

cambium 29 Jun, 2018
Hello!
Is it possible to add the some records to a database at once using one Save Data action?
I have the multidimensional array (returned by code of PHP action), which used as data source in Save Data action [pre] $results = array(array ('field_id' => 4, 'item_id' => $art_id, 'value' => $med1),
array('field_id' => 5, 'item_id' => $art_id, 'value' => $med2),
array('field_id' => 6, 'item_id' => $art_id, 'value' => $med3),
array('field_id' => 7, 'item_id' => $art_id, 'value' => $med4),
array('field_id' => 8, 'item_id' => $art_id, 'value' => $medip) );[/pre]The field "Write action" value (in Save Data) is "Insert - duplicate key update".[br]On submit event i get that error "1054Unknown column '0' in 'field list'.[br]What can i do with it?[br][br]Many many thanks for answer
GreyHead 30 Jun, 2018
Answer
Hi s.elena133,

Please check the Data Iteration section on page 25 of the CFv6 manual.

Bob
cambium 30 Jun, 2018
Hi Bob,
It works!
Thanks for you answer.

And the one more question about Save Data action.
The db table i try to modify has the key including two fields. I use the "Insert - duplicate key update" setting.
The writing conditions are:
fields_values.item_id:{var:php26}
AND
(
fields_values.field_id:4
OR
fields_values.field_id:5
OR
fields_values.field_id:6
OR
fields_values.field_id:7
OR
fields_values.field_id:8
)
But it does not update the records having duplicate keys, but insert the all array of records every once.
And more i get an error: "Notice: Undefined index: value in Z:\home\medical-db\www\libraries\cegcore2\admin\extensions\chronofc\functions\save_data\save_data_output.phpon line42".
What wrong i did?
GreyHead 01 Jul, 2018
Hi s.elena133,

Please add a Debugger action to your form so that you can see the queries that are being generated to save the data. That should help you work out what exactly is happening here.

The PHP message is a notice, not an Error so the code should still run OK. You can hide it by setting your site Error Reporting to System Default or to None.

Bob
cambium 01 Jul, 2018
Hi Bob,
Ok. I'll try.

Thank you for your answers
This topic is locked and no more replies can be posted.