This topic is locked

Performing calculation and graph

7/21/2008 12:44:45 AM
PHPRunner General questions
B
bosco author

I have 2 tables. "User Table" and "Order Table".
Using master/detail relationship, I can link OrderID in both the table.
"User Table" has a field "amount paid". Then, in the "Order Table", there will be multiple "order id" with its "price".
I would like to know how to perform calculation. Example, total up all the prices from the same "order id" then refer back to the "User Table" to minus the "amount paid". The result will then be stored in the master table, let's say "change".
I need this so that I can make a graph on "change".
Thanks.

J
Jane 7/21/2008

Hi,
to update master table use After record added event for Order table on the Events tab.

Here is a sample:

global $conn;

$str = "select sum(price) as `sum_price` from `Order` where `OrderID`=".$values["OrderID"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
$strUpdate = "update `User` set `total`=".$data["sum_price"]."-`amount paid` where `OrderID`=".$values["OrderID"];

db_exec($strUpdate,$conn);