I have a table with checks of different worths and customers can place orders and use part of said checks to pay over time.
ex.
tblChecks:
check1-worth 50€
check2-worth 20€
tblPayments:
order1-worth 25€
I want that 25€ be subtracted first from check2 leaving it at 0, and the remaining 5 from check1 leaving it at 45.
I thought of the following routine: use an array to order the results of the SQL (something like SELECT checkID FROM tblChecks WHERE worth > 0), and said array then be used in a for loop to do the math and attain expected results.
Unfortunately, though, I wouldn't know how to code it, plus if anyone comes up with a better solution I'm looking forward to hearing from them.
ex.
tblChecks:
check1-worth 50€
check2-worth 20€
tblPayments:
order1-worth 25€
I want that 25€ be subtracted first from check2 leaving it at 0, and the remaining 5 from check1 leaving it at 45.
I thought of the following routine: use an array to order the results of the SQL (something like SELECT checkID FROM tblChecks WHERE worth > 0), and said array then be used in a for loop to do the math and attain expected results.
Unfortunately, though, I wouldn't know how to code it, plus if anyone comes up with a better solution I'm looking forward to hearing from them.