This topic is locked
[SOLVED]

 Master Table Update from Detail Table Totals

3/26/2016 12:19:15 PM
PHPRunner General questions
A
azmi author

Hi All,

I have a Master /Detail Table and using PHPRUNNER 8.1

I want to sum value from Detail table to Update one field of Master Table.

Master Table : field Name = Inv_total

Detail Table: Select SUM(Qty*Rate) AS Inv_tot from Detail

What would be the script and where to be place.

Sergey Kornilov admin 3/28/2016

Here is the sample code below. You can use it in AfterAdd/AfterEdit event of details table.

$sum = DBLookup("Select SUM(Qty*Rate) AS Inv_tot from Detail where MasterTableID=".$values["MasterTableID"]);

CustomQuery("Update MasterTable set inv_tot=".$sum." where MasterTableID=".$values["MasterTableID"]);



There are some missing parts here like master table name, or names of link fields from both master and details.