webref.eu Posted August 23, 2006 Share Posted August 23, 2006 Hi AllIf I have an SQL query which yields no results, what is the syntax for testing there are no results in an If statement? FYI my code uses the following: //assign query results to a result variable$result = mysql_query($query); if(!$result) die("Query Failed.");//associative array allows you to use field names to get resultswhile($row = mysql_fetch_array($result, MYSQL_ASSOC)Many thanksWebRef.eu Quote Link to comment https://forums.phpfreaks.com/topic/18466-resolved-syntax-for-if-no-results-from-query/ Share on other sites More sharing options...
AndyB Posted August 23, 2006 Share Posted August 23, 2006 mysql_num_rows() ... if it's a valid query Quote Link to comment https://forums.phpfreaks.com/topic/18466-resolved-syntax-for-if-no-results-from-query/#findComment-79479 Share on other sites More sharing options...
448191 Posted August 23, 2006 Share Posted August 23, 2006 For select queries use mysql_num_rows($result) like andy said. For update, delete or insert queries use mysql_affected_rows(). Quote Link to comment https://forums.phpfreaks.com/topic/18466-resolved-syntax-for-if-no-results-from-query/#findComment-79489 Share on other sites More sharing options...
webref.eu Posted August 23, 2006 Author Share Posted August 23, 2006 Thanks guys, that's great.RgdsWebRef.eu Quote Link to comment https://forums.phpfreaks.com/topic/18466-resolved-syntax-for-if-no-results-from-query/#findComment-79503 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.