UPDATE table
SET
amount -= '$amount'
WHERE
type = '1' AND
amount - '$amount' >= '0'
Okay, let´s explain. If I have two rows in my table:
type | amount
1 | 30
1 | 20
Altogether I want to subtract whatever $amount is, from rows where type is equal to 1. So if $amount holds number 40, that means that I altogether want to subtract 40 and get this result:
type | amount
1 | 0
1 | 10
(30 from row 1 and 10 from row 2, that means 40 has been subtracted)
So if one row doesn't cover the number in $amount I want to continue subtracting on another row. But if not even every row together cover $amount, no subtracting shall be made.
Which is the easiest way to manage this?
I use PHPMyAdmin.
Thanks for your help!