View Single Post
Old 02-26-2008, 05:07 PM   #1 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default Complicated MySQL if statement/update

Right I'm trying to do the following:

(pseudo)

Code:
update tablename set `cash` = ( IF cash - # > 0 SET `cash` = `cash` - # ELSE SET `cash` = 0) WHERE uid = 1
How do I do this?

Someone said to use this yet I think its not how I think its supposed to be setup:

Code:
UPDATE `mem` SET `uM` = (
    SELECT IF ((SELECT (`uM` - %d) FROM `mem` WHERE `uid` = %d) > 0), 
                         (SELECT (`uM` - %d) FROM `mem` WHERE `uid` = $d), 
                          0
                          )
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote