I'm wanting to decrement a variable in a MySQL table by one everytime an UPDATE query is ran.
What I have is this, which isn't working:
UPDATE forum SET replys = reply-- WHERE fid = '$id'
Is this possible in any way, or am I going to have to run a SELECT and get the value first, decrement it, and then insert the new value into the UPDATE query?
If you want to OVERWRITE always, (not update, just overwrite) you can use REPLACE instead of INSERT . WARNING: DO NOT use REPLACE if there are other tables with foreign key indexes referring to the table you are updating.
UPDATE forum SET replys = reply - 1 WHERE fid = '$id'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With