spikypunker Posted May 8, 2009 Share Posted May 8, 2009 How do i achieve this? I've been planning out a new bit for a page on my site, and i know that currently, if any of my requests come back blank ie "SELECT from table WHERE venue='o2 arena' " And there IS NO 'o2 arena' in the database, instead of displaying nought, it displays some error messages. In the new bit for my site, at first most of the time it will coming back empty! So how do i do an, IF EMPTY { } else {} ?? :os Quote Link to comment https://forums.phpfreaks.com/topic/157376-if-nothing-matches-the-variable-in-the-field-display-nothing/ Share on other sites More sharing options...
premiso Posted May 8, 2009 Share Posted May 8, 2009 mysql_num_rows if (mysql_num_rows($result) < 1) { echo "Query returned no results."; } Where $result is the resource of mysql_query Quote Link to comment https://forums.phpfreaks.com/topic/157376-if-nothing-matches-the-variable-in-the-field-display-nothing/#findComment-829587 Share on other sites More sharing options...
xXREDXIIIXx Posted May 8, 2009 Share Posted May 8, 2009 Im not an expert but this should work. if($row['arena'] == NULL){//Show nothing} else {//Show this} Quote Link to comment https://forums.phpfreaks.com/topic/157376-if-nothing-matches-the-variable-in-the-field-display-nothing/#findComment-829588 Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 8, 2009 Share Posted May 8, 2009 You can count the number of result after the query like that : $sql = "SELECT from table WHERE venue='o2 arena'"; $result = mysql_query($sql); if (!$result) { die('Invalid query: '.$sql.' -- '.mysql_error()); } if (mysql_num_rows($result) > 0) { /* display your data */ } else { echo "No results."; } Quote Link to comment https://forums.phpfreaks.com/topic/157376-if-nothing-matches-the-variable-in-the-field-display-nothing/#findComment-829591 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.