This topic is locked

Insert Multiple records by dropdown

2/22/2022 4:25:29 AM
PHPRunner General questions
C
Cornelius Smit author

How can I insert multiple records in a table from another table based on the selection i made from a dropdown then press custom button to do the job

I have a dropdown(job type) in table A(Invoce),I need to insert records from table C(PartsList) to Table B(invoice details) based on a dropdown in table A getting the type from table E(job Type)
IOW
Insert records from table C with the same job type into table B when button pressed
Hope it make sense
TIA

K
kohle 2/22/2022

Hi,

Here is like I would do it. The code is only an example .

  1. On the tab tables I define a relation between the invoice and the invoice details table.
    I use the unique key field : id_invoice.


  2. On the tab pages I declare the id_invoice field as key field (right upper corner)


  3. In the designer tab I choose invoice details and add a custom button


  4. In the custom button server tab I add a similar code like this :



$record = $button->getMasterRecord(); //Relation table A and B

$type = $record['jobtype']; //get job type from table A
$id_invoice = $record['id_invoice']; //get unique ID from table A (invoice ID)

$sql = "select * from t_partslist where jobtype = ".$type; //if alphanum than put in ''
$rs = DB::Query($sql);
while ($data = $rs->fetchAssoc())
{
$sql2 = "INSERT INTO t_invoice_details (id_invoice, job_type, desc, qty, price )
VALUES (" . $id_invoice . "," . $type . ", '" . $data['desc'] . "', " . $data['qty'] . ", " . $data['price'] .")";

DB::Exec($sql2);
}