niche Posted December 23, 2011 Share Posted December 23, 2011 I'm trying to write an if in a mysql query. Based on: http://dev.mysql.com/doc/refman/5.0/...statement.htmlI came up with this, but no joy. 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? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 23, 2011 Share Posted December 23, 2011 The reference you linked to is for functions, not SQL queries. This is for queries: http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if The if statement returns a value, so that value would be the value for the field to update. e.g.: UPDATE table SET field = IF(...) WHERE .... Link to comment Share on other sites More sharing options...
niche Posted December 24, 2011 Author Share Posted December 24, 2011 Thanks justsomeguy. I'll look in to that. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.