SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    if in mysql_query

    I've never done an if in a mysql query. Based on: http://dev.mysql.com/doc/refman/5.0/...statement.html
    I came up with this, but no joy.

    PHP Code:
    mysql_query("UPDATE skew_trkg_slave IF observations_needed = observations_completed THEN SET minor_cycle_completed = '1'; WHERE " $skew_trkg_slave_where "") or die(mysql_error()); 
    How close am I?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    UPDATE skew_trkg_slave
       SET minor_cycle_completed = 1
     WHERE observations_needed = observations_completed
       AND $skew_trkg_slave_where
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much r937. Could that have been done with a if statement? If so, how would it be written the the procedural style?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by nichemtktg View Post
    Could that have been done with a if statement?
    no, because an IF statement is used for flow-of-control execution, not to evaluate column contents in each row
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks again r937. I'll look into flow-of-control execution. It sounds like something I should at least know about.


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
  •