[SOLVED] Â Mixing multiselect insert code with other code |
8/17/2019 10:47:05 AM |
PHPRunner General questions | |
D
david22585 author
I'm looking to use the multiselect values to individual database record code, and after a lot of research that it needs to be a VARCHAR field instead of a INT field, I got it to work for inserting the records as individual records. Here is the code I used: if ($values["account_id"])
DB::Query("update accounts_data set balance=balance + ".$values["debit"]." where id = ".$values["account_id"]."" );
$sql = "SELECT(balance) AS total FROM accounts_transactions where account_id = ".$values["account_id"]." ORDER BY id DESC LIMIT 1";
|
|
![]() |
Sergey Kornilov admin 8/17/2019 |
What kind of problem you are facing running all these code snippets together? |
D
|
david22585 author 8/17/2019 |
What kind of problem you are facing running all these code snippets together?
DB::Query("update accounts_data set balance=balance + ".$values["debit"]." where id = ".$values["account_id"]."" ); $sql = "SELECT(balance) AS total FROM accounts_transactions where account_id = ".$values["account_id"]." ORDER BY id DESC LIMIT 1";
|
D
|
david22585 author 8/21/2019 |
After a lot of different methods, I was able to get this to work. I can use this code to create a transaction log to generate statements, along with updating the balance on a given account. I have 2 tables, 1 that holds the user account information with the current balance (accounts_data), and another that has a list of all transactions for all accounts (accounts_transactions). Lets say you do monthly billing and want to bill each account $50/month, or lets say add a $10 late fee every month to a list of accounts. Doing it 1 by 1 would be tedious for a large number of accounts. With this code,every account that you select will update their current balance on the accounts_users table, and insert an entry into the account_transactions table with the bill amount (debit), along with reading their last balance and providing an updated balance to create statements so a user can see their transactions. // Updates the account data current balance |