Forum Moderators: coopster

Message Too Old, No Replies

PHP/Mysql (NULL+X)?

Is it possible?

         

ajs83

3:41 am on Jan 26, 2006 (gmt 0)

10+ Year Member



Is it possible to setup a mysql insert that instead of just inputting 'NULL' allows me to do something like 'NULL+10' (it takes the next number and then adds 10 to the db entry)?

FalseDawn

7:41 am on Jan 26, 2006 (gmt 0)

10+ Year Member



To save people guessing at what you are asking, you'll probably get a (better) answer if you explain your requirements a little more clearly.

Salsa

10:02 am on Jan 26, 2006 (gmt 0)

10+ Year Member



You can't add or subtract from NULL because NULL isn't even nothing. It's no data. You can do an UPDATE condition like this, however.

UPDATE table SET field = IF(field IS NULL, 10 , field + 10);

If I'm understanding what you want, that way you can keep records with no data set to NULL and replace it when you do have data, or if data already exists, add to the current value.

I hope that helps,
Salsa
________

ajs83

10:26 pm on Feb 2, 2006 (gmt 0)

10+ Year Member



What I want to do is basically take whatever number that is being entered in the NULL field (by using auto increment in mysql) and add 10 to that before the data is entered into the db.