tags:

views:

257

answers:

2

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?

+6  A: 

UPDATE forum SET replys = reply - 1 WHERE fid = '$id'

stu
sometimes it's so simple you just want to yell... thanks, that worked perfectly.
kylex
bugger! typed too slowly.
duffymo
+2  A: 

of course:

UPDATE forum SET replies=replies-1 WHERE fid = ?
duffymo