How to always update by adding+1 to mysql

Asked

Viewed 394 times

3

Hello,

How do I update a mysql column by always inserting +1 with each new update? And how to take -1 from the same column ?

I tried that:

"UPDATE tb_comment SET good=+1 WHERE id=:idComment"

Only that inserted only 1, did not continue counting 1.. 2..3.4. according to the updates I gave..

And to get a record I tried it:

UPDATE tb_comment SET good=-1 WHERE id=:idComment

And I failed miserably

1 answer

2

Solved!!

This is what I’d do:

"UPDATE tb_comment SET good=good+1 WHERE id=:idComment"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.