Thread: IF/THEN

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    43
    Rep Power
    15
    Can you do If/Then statements in Mysql? If so a little help would be appreciated (a brief example). Basically, I want to create a new variable with a certain value depending on the relationship between two other variables.

    If you can't do this, I'm sure there is some way around this using queries. Is this the case?

    Thanks
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    IF (expr1,expr2,expr3)

    Returns expr2 if expr1 is true, else returns expr3

    so your select would look like:

    select IF(some_field=something,'True','False') as somename where foo;

    That's as specific as I can get from your description.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    43
    Rep Power
    15
    Thanks for the help, I'll try and be more specefic, because I don't clearly understand your reply especially the "somename where foo;" part:

    Say I have a persons answers to a question, ANSWER1, and then I also have the correct answer, call it field CANSWER1. So I want to be able to assign points to another field POINTS depending on whether the answer is correct. I want to update this POINTS field for all of the questions I have. Does this make since?

    Thanks again.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by rod k:
    IF (expr1,expr2,expr3)

    Returns expr2 if expr1 is true, else returns expr3

    so your select would look like:

    select IF(some_field=something,'True','False') as somename where foo;

    That's as specific as I can get from your description.
    [/quote]

Similar Threads

  1. Basic If/Then statement
    By Carl Conrad in forum PHP Development
    Replies: 11
    Last Post: October 19th, 2003, 12:55 PM
  2. if/then within MySQL results list
    By BicyclePunk in forum PHP Development
    Replies: 6
    Last Post: May 19th, 2003, 10:09 PM
  3. using file last modified date in if/then statement
    By gennyblake in forum HTML Programming
    Replies: 3
    Last Post: February 16th, 2003, 05:02 PM
  4. if/then to check if value is integer
    By cuboctahedron in forum MySQL Help
    Replies: 5
    Last Post: February 12th, 2003, 06:38 AM
  5. javascript document.title if/then?
    By gennyblake in forum JavaScript Development
    Replies: 2
    Last Post: December 13th, 2002, 11:29 AM

IMN logo majestic logo threadwatch logo seochat tools logo