This topic is locked

Simple Running Balance

11/21/2008 11:58:29 AM
PHPRunner General questions
bbarker author

I can't seem to modify the code that is listed in the Tips section.
NEEDED:
Table: financial
IDmember----received----------refunded-------------Balance

5-----------------95.00--------------30.00-------------$65.00

5----------------- 5.00--------------20.00-------------$50.00

5-----------------25.00---------------0.00-------------$75.00

etc
This code adds and inserts into the Balance, the correct total, but doen't increment it for the next row.
[codebox]global $data,$conn;
$str = "select sum(received) - sum(refunded) from financial

where IDmember=".$_SESSION[$strTableName."_masterkey1"];
$rs = db_query($str,$conn);
$data = db_fetch_numarray($rs);
$value = $data[0];[/codebox]
When I add this to the code I get undefined variable or constant error, depending upon where I add it.
[codebox]for($i=0;$i<count("received");$i++)

{

<<previous code>>

}[/codebox]
I've spent 8 hours looking through samples on Safari, but continue to get an error no matter what I use.... Also tried count().
Could someone help me out? Many thanks, in advance.

J
Jane 11/24/2008

Bill,
to calculate Balance use Before record added/updated events on the Events tab.

Here is just a sample:

global $data,$conn;

$str = "select sum(received) - sum(refunded) from financial

where IDmember=".$_SESSION[$strTableName."_masterkey1"];

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

$data = db_fetch_numarray($rs);
$values["Balance"] = $data[0]+$values["received"]-$values["refunded"];