I am inserting multiple records into a database. Many of the fields are consistent, but one field is calculated, and needs to calculate/subtract the value for each record inserted into the database.
<?php
$ExecuteQuery = new WA_MySQLi_Query($numeroseti);
$ExecuteQuery->Statement = "INSERT INTO transactions
(fromAcct, amount, fromAcctNewBalance, toAcctNewBalance, toAcct, description, timestamp)
(SELECT 1, ?, ?, balance + ?, acct_number, 'issuance', $time FROM users WHERE acct_number NOT LIKE '1800%' AND type <> 1 AND user_active = 1)";
$ExecuteQuery->bindParam("d", "".($_POST['issue_balance']) ."", "0"); //acct1num
$ExecuteQuery->bindParam("i", "".($getSender->getColumnVal("balance") - $amount) ."", "-1");
//acct2num
$ExecuteQuery->bindParam("i", "".($amount) ."", "-1");
//acct3num
$ExecuteQuery->execute();
?>
The field is fromAcctNewBalance
that I am having issues with. This is the code that calculates (like a ledger) what the new balance is:
$getSender->getColumnVal("balance") - $amount;
The problem is, it puts the same value into each record, when it should be subtracting the amount each time a new record is added.
For example, if the fromAcctNewBalance
starting balance is 600 and the amount issued to a user is 10, and next record that is added should have a fromAcctNewBalance
of 590, and so on, until it runs out of records to add to the table.
Does anyone have any ideas on how I can fix this issue?