lefty 6/9/2019 | |
I was able to get this to work before, but I can't get it to work anymore for some reason. What I was looking to get done was have a transaction log for banking/account balance purposes. This is for a small organization, so once a value is added, they cannot go back to edit the cost. I have the following setup: Table 1 (bod_account) -Account ID -Account Name Table 2 (bod_transactions) -credit -debit -balance I have separate Add Expense and Add Deposit pages. Using the Add Deposit Page, I have the following code: Before Record Added: $sql = "SELECT MAX(balance) AS total FROM bod_transactions";
CustomQuery("update bod_account set balance=balance+" . $values["credit"] . " where account_id = 1" );
|
D
|
david22585 author 6/9/2019 |
Have You tried one of two options. After Record Added. with the same query and change $data to $values. OR Before Record Added $sql = "SELECT MAX(balance) AS total FROM bod_transactions"; $rs = CustomQuery($sql); $data = db_fetch_array($rs); $values['balance'] = $[size="2"]values[/size]["total"] + $values["credit"]; //[size="3"]not data[/size] : it's not a button correct? AND total is an alias and not withstanding a field called total and and an alias called total???
$values instead of $data or vice versa. The total is an alias from the data in the balance column of the database where the value is stored. Since I got that solved, I also found that my sql query of selecting MAX would return the highest number and not the last transaction id balance. Through trial and error, I was able to solve it with the following code: $sql = "SELECT(balance) AS total FROM bod_transactions ORDER BY id DESC LIMIT 1";
CustomQuery("update bod_account set balance=balance+" . $values["credit"] . " where account_id = 1" );
$sql = "SELECT(balance) AS total FROM bod_transactions ORDER BY id DESC LIMIT 1";
CustomQuery("update bod_account set balance=balance-" . $values["debit"] . " where account_id = 1" );
|