This topic is locked

Insert Multiple Records into Child Table

4/20/2023 8:35:14 AM
PHPRunner General questions
C
CWDATA author

Quick bit of advice please.
Can you adapt the code for Before Add Insert to insert more than one field?
Standard Version
global $dal;
$tblDetail = $dal->Table("tblUserRequests");
$tblDetail->Value["ID"] = $data["ID"];
$tblDetail->Param["ID"] = $data["ID"];
$tblDetail->Update();
unset($data["ID"]);
What I would like to do is add another one or two fields so ID, client and user. If this can be done how should the code be structured please?

W
wedi 4/22/2023

Hello @cwdata
in your headline you write "multiple records" and in your description you want to add one or two fields?
No matter. I would solve it with DB::Exec.
for new record
$sql = "insert into child_table (ID, field1, field2, field3, ...) Values(" . $data["ID"] . ", valField1, valField2, valField3, ...)," <-- use ' ' when field is a character
for update record
$sql = "update child_table set field1 = valField1, field2 = valField2, field3 = valField3, ... where ID=" . $data["ID"]";
$rc = DB::Exec($sql);
if ( !$rc ) {
for example show message
and return false;
}
I hope I have not misunderstood you.
Regards,
wedi

C
CWDATA author 4/22/2023

Hi @wedi
Your right the headline should be worded better.
I will try to impliment your solution. Where you have valField1 does that refer to a specific value or can it refer to the field from which the value I require is drawn?
Cheers.

W
wedi 4/22/2023

valField1 is a placeholder for what ever you want to save to Field1 or 2 or 3 and so on. It can be a fix value or $data['xxxx'] or something else.
wedi

C
CWDATA author 4/25/2023

I have decided to take a different approach. I am going to make use of session variables.But a big thanks to WEDI for taking the time to reply to my query it is much appreciated.