drranch Posted November 25, 2007 Share Posted November 25, 2007 I have four MYSQL row results, where I want to display a message if all of the row results are empty. This is my code... if ($row_rsnotifier == null && $row_hmnotifier == null && $row_rsvcnotifier == null && $row_rshcnotifier == null) echo "There are no appointments scheduled for the next 7 days."; The above code will display my message if all are empty, but it will also display the message if one isn't empty. If all are not empty it won't display my message. Any suggestions? Quote Link to comment Share on other sites More sharing options...
nuxy Posted November 25, 2007 Share Posted November 25, 2007 Take a look at mysql_num_rows() and the COUNT(*) function in mysql. Method 1; <?php $query = mysql_query("SELECT `message` FROM `table`"); if (mysql_num_rows($query) <= 0) { echo 'No results'; } ?> Method 2; <?php $query = mysql_query("SELECT COUNT(*) FROM `table`"); if (mysql_result($query,0) <= 0) { echo 'No results'; } ?> Quote Link to comment Share on other sites More sharing options...
drranch Posted November 26, 2007 Author Share Posted November 26, 2007 That won't work because there are four different queries. Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 26, 2007 Share Posted November 26, 2007 if ($row_rsnotifier == null && $row_hmnotifier == null && $row_rsvcnotifier == null && $row_rshcnotifier == null) echo "There are no appointments scheduled for the next 7 days."; The above code will display my message if all are empty, but it will also display the message if one isn't empty. If all are not empty it won't display my message. Any suggestions? Huh? This is strictly AND statement wherein all conditions must be met to execute the next statement. Have you checked the value of the variables? Are you sure the data is NULL and not an empty string? if ($row_rsnotifier == null) echo "Var 1: OK"; if($row_hmnotifier == null) echo "Var 1: OK"; if($row_rsvcnotifier == null) echo "Var 1: OK"; if($row_rshcnotifier == null) echo "Var 1: OK"; Quote Link to comment Share on other sites More sharing options...
drranch Posted November 27, 2007 Author Share Posted November 27, 2007 empty string... I have four possible appointments to display for an end user on their home page. At any given time any one of these types of appointments can have no available appointments.. if appt1 exist echo appt1 date if appt2 exist echo appt 2 date if appt3 exist echo appt 3 date if appt4 exist echo appt 4 date else if there are no appointments for any appointment type 1 through 4 echo "there are no appointments scheduled for the next 7 days. Quote Link to comment Share on other sites More sharing options...
drranch Posted November 27, 2007 Author Share Posted November 27, 2007 <php? if ($appt1 exist !=null){ echo "appt1 appointment date" }else if ($appt2 exist !=null){ echo "appt2 appointment date" }else if ($appt3 exist !=null){ echo "appt3 appointment date" }else if ($appt4 exist !=null){ echo "appt4 appointment date" }else{ echo "There are no appointments scheduled for the next 7 days." ?> Its working very nicely... Now on to the time side of appointments. 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.