Reputation: 119
So i have a question. I have no idea how i need to insert a search in google for it so i'm going to ask it here.
I have like 50.00 euro. in mysql table it is showed as
Id | Username | Balance
1 | Kev | 50.00
Now when i buy something that is worth like lets say 5.00 euro it would be 50.00 - 5.00 = 45.00 euro left on balance
Id | Username | Balance
1 | Kev | 45.00
Now my question is. How do i do this with a simply get old balance then insert the new balance into the table? Also i'm using PDO
Sorry for my nooby question but i have no idea how to insert this into a search in google.
~Kev
Upvotes: 0
Views: 82
Reputation: 12433
You can update a row by setting the column equal to the current column value minus (or plus) another value
UPDATE `table` SET `Balance` = `Balance`-5.00 WHERE `Username`='Kev'
or
UPDATE `table` SET `Balance` = `Balance`-5.00 WHERE `Id`=1
Upvotes: 1