Kaitosoto Posted February 18, 2007 Share Posted February 18, 2007 This should be simple. After using PHP to connect to a MySQL database, how do I make an IF statement with a query? like, I know that when you do something like $sql = "UPDATE fdatabase SET blah blah blah"; $query = mysql_query($sql,$connect); It connects to the thing. How do I make it so that it is conditional like this: if(-MYSQL QUERY THAT SELECTS A VALUE FROM one of THE fdatabase tables- = 0) { $sql = "UPDATE fdatabase SET blah blah blah"; $query = mysql_query($sql,$connect); } else { -do nothing } Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 18, 2007 Share Posted February 18, 2007 If you want to check if the update has happened then check mysql_affected_rows($query) == 0 Quote Link to comment Share on other sites More sharing options...
Kaitosoto Posted February 18, 2007 Author Share Posted February 18, 2007 No, I want to check to see that the value that was found with the SELECT in the first query was greater than 0. If so, then execute the second query. Quote Link to comment Share on other sites More sharing options...
fert Posted February 18, 2007 Share Posted February 18, 2007 http://us2.php.net/manual/en/function.mysql-num-rows.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.