This topic is locked

How to insert total from detail table to master table field?

3/26/2020 8:19:50 PM
PHPRunner General questions
dgmax2010 author

How to insert total from detail table to master table field?
As a PHP/MySQL newbie, I'd appreciate some help in setting up an event action in PHPrunner which will take the total of series of numeric entries in a detail (child) table and insert the value into a field in the corresponding master table.
The background to this is a sales database listing sales in the master table with separate individual payments recorded in the detail table, the total of which is then inserted into the master entry which calculates the balance.
Many thanks in advance!
Try this not work
global $strTableName,$dal;

$rs = CustomQuery("select sum(FieldName) from DetailTableName where DetailKey=".$_SESSION[$strTableName."_masterkey1"]);

$data = db_fetch_numarray($rs);
$dal->MasterTableName->Value["TotalFieldName"] = $data[0];

$dal->MasterTableName->Param["MasterKey"] = $_SESSION[$strTableName."_masterkey1"];

$dal->MasterTableName->Update();

N
Nir Frumer 3/26/2020



How to insert total from detail table to master table field?
As a PHP/MySQL newbie, I'd appreciate some help in setting up an event action in PHPrunner which will take the total of series of numeric entries in a detail (child) table and insert the value into a field in the corresponding master table.
The background to this is a sales database listing sales in the master table with separate individual payments recorded in the detail table, the total of which is then inserted into the master entry which calculates the balance.
Many thanks in advance!
Try this not work
global $strTableName,$dal;

$rs = CustomQuery("select sum(FieldName) from DetailTableName where DetailKey=".$_SESSION[$strTableName."_masterkey1"]);

$data = db_fetch_numarray($rs);
$dal->MasterTableName->Value["TotalFieldName"] = $data[0];

$dal->MasterTableName->Param["MasterKey"] = $_SESSION[$strTableName."_masterkey1"];

$dal->MasterTableName->Update();


hi

in most cases,

Adding a calculated field (or fields) to your master table query -

do the job

and saves these updates.
hope it helps,

Nir.