tags:

views:

86

answers:

7

Hello guys.. I have data which is starting from 0 in my database.

My php will add 1 or -1 to the data depending on the user's input. My problem is that if data is 0 and a user try to subtract 1. The data become 4294967295 which is the maximum value of INT data type. Are there anyways to make the data stays in 0 even when the user asks for -1? Thanks for the reply..

my sql command is like below

update board set score=score-1 where team='TeamA'
//this would generate 4294967295 if the score is 0.....
+7  A: 

Yes..

UPDATE board SET score = score - 1 WHERE team = 'TeamA' AND score > 0
Ian P
Thanks a lot :D
Jerry
+3  A: 
update board set score=score-1 
where team='TeamA'
and score > 0
Martin Smith
Thanks for the answer. +1 :D
Jerry
+1  A: 

Why not just add AND SCORE > 0

drachenstern
A: 
ALTER TABLE board MODIFY score UNSIGNED INT;
Piskvor
It's already an unsigned int; he's trying to prevent his UPDATE from underflowing a row that has a 0 score (the title is admittedly confusing)
Michael Mrozek
He's saying he's getting 4294967295 so I assume it is unsigned but wrapping around.
Martin Smith
Ah, silly me. Serves me right for not reading it correctly...
Piskvor
A: 

Did you set your column as unsigned?

Inkspeak