Mysql update event

Asked

Viewed 90 times

0

I asked this question yesterday, I got the answer I wanted, I’ll be straight and straight:

I have the query:

UPDATE users SET time = time - 1

time is the type int and receives as default value 0, in my PHP code I made a scheme where the user clicks on the add button 1800 in the value of time and the query event up there goes into action, it turns out that when it gets to 0 it starts counting -1,-2,-3...-1800 etc, wanted to make it crash when it gets to 0

How can I do this?

1 answer

2


You can do it two ways for me.

  1. Update whenever the WHERE clause returns true to the condition time > 0. Example: UPDATE tabela SET time = time - 1 WHERE time > 0.

  2. Update your table to that field time has the attribute UNSIGNED. This means that your field can only have non-negative numbers, according to the Mysql documentation. Example: ALTER TABLE tabela MODIFY COLUMN time int(10) UNSIGNED ZEROFILL.

Behold: UNSIGNED and ZEROFILL: What are columns for in Mysql

  • Thank you saved my life and my brother’s kkkk he ta creating a website and me another, detail: left as UNSIGNED

Browser other questions tagged

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