Jump to content

[SOLVED] displaying msg with null row results


drranch

Recommended Posts

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?

Link to comment
Share on other sites

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';
}
?>

 

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<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.  ;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.