How to insert multiples records on another table from multiples records forms

I will apreciate if somebody can help me with the code on event onAfterUpdate

When I exec this code, just insert one row, but I need to insert all rows from form.
Thank you in ADVANCE
BERNARDO

My code.

$respuesta = {respuesta};

$sql = “INSERT INTO resultado_encuesta (nota_1)
VALUES (’$respuesta’)”;

sc_exec_sql($sql);

sc_commit_trans();
sc_redir(form_item_encuesta1);

Can you explain a bit more? You have a multi-record form? Or a grid or…?

How to insert multiples records on another table from multi-record form

I have a multi-record form

Thak you Albert

You need to collect the primary keys of the records to be copied over.

onScriptInit: [selected] = array();

onAfterUpdate: [selected][] = {primary_key};

onAfterUpdateAll:

if(count([selected]) > 0)
{
$tocopy = ‘(’.implode(’,’,[selected]).’)’;
$sql = “INSERT INTO table2 (SELECT what_you_need FROM table1 WHERE primery_key IN $tocopy)”;
sc_exec_sql($sql);
[selected] = array();
}

That’s the basic idea, it might need to be refined for your situation.

jsb

Hi Jsb, thank you for your answer

Code you sent me, you are taking the records from table1, to copy in table 2, however I just need to copy the field from my multi-record form, because this field I want to copy doesn’t exist in a table.

following code is working but it copy the first row only and I would like to copy ten or more rows:

$respuesta = {respuesta}; “/this field only exists in form not in a table/”"

$sql = “INSERT INTO resultado_encuesta (nota_1)
VALUES (’$respuesta’)”;

sc_exec_sql($sql);

Well, ther is not much difference.
onScriptInit: [selected] = array();

onAfterUpdate: [selected][] = “(’”.{respuesta}."’)"; //watch the quotes

onAfterUpdateAll:

if(count([selected]) > 0)
{
$tocopy = implode(’,’,[selected]);
$sql = “INSERT INTO resultado_encuesta (nota_1) VALUES $tocopy”;
sc_exec_sql($sql);
[selected] = array();
}

That should do it.

jsb

Thank you very much jS, it works pefectly!!

Bernardo