SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    323
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    PHP SQL Conditional queries?

    I'm trying to do a query like this:

    PHP Code:
    $u=mysql_query("UPDATE `Member` IF `prem_days` > '0' THEN `prem_days` = `prem_days` - 1 ELSE `premium` = 'no' AND `prem_days` = '0'") or die(mysql_error()); 
    But this doesn't seem to work. The other alternative is to use two queries but I'd rather not as my DB is very query intensive as it is already :P

    Any help with this would be greatly appriciated ^_^

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    before running a query that modifies data, make sure you have a backup and that you know how to restore it properly!

    one of these two will work. i don't have time to test if for you right now, so i suggest using a transaction to verify which one is correct.
    Code:
    UPDATE Member
       SET prem_days = GREATEST(0, prem_days - 1)
         , premium = CASE prem_days WHEN 0 THEN 'no' ELSE premium END
    Code:
    UPDATE Member
       SET prem_days = GREATEST(0, prem_days - 1)
         , premium = CASE prem_days - 1 WHEN 0 THEN 'no' ELSE premium END
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast

  3. #3
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    323
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •