Page 1 of 1

auto table update in sql hook

Posted: 2017-05-04 14:54
by Mahmud
i have two table

1. FUNDED_TRANSACTION when BALANCE update
2. FUNDED_BANK_SUMMARY then this table BALANCE update
function FUNDED_BANK_SUMMARY_before_insert(&$data, $memberInfo, &$args){
$data['AVAILABLE_BALANCE'] = $data['LOAN_LIMIT'] - $data['BALANCE'];

by hook work ok....

but problem is when FUNDED_TRANSACTION BALANCE update then FUNDED_BANK_SUMMARY this table BALANCE not auto update .

how can i do

Re: auto table update in sql hook

Posted: 2017-05-13 19:41
by Mahmud
solved :
---------------
if($ACCOUNT_NAME){
$ACCOUNT_NAME_BALANCE = sqlValue("select sum(if(TRANSACTION_TYPE in ({$positive_funded_transaction}), BALANCE, -1 * BALANCE)) from funded_transaction where ACCOUNT_NAME={$ACCOUNT_NAME}");
sql("update funded_bank_summary set BALANCE='{$ACCOUNT_NAME_BALANCE}' where id={$ACCOUNT_NAME}", $eo);
mysql_select_db('bank',mysql_connect('localhost','bank',''))or die(mysql_error());
$query=mysql_query("select * from FUNDED_BANK_SUMMARY where id={$ACCOUNT_NAME} ")or die(mysql_error());
$row=mysql_fetch_array($query);
$ALANCE=$row['LOAN_LIMIT']- $row['BALANCE'];
sql("UPDATE FUNDED_BANK_SUMMARY SET AVAILABLE_BALANCE= '{$ALANCE}' where id={$ACCOUNT_NAME}", $eo);

}