Below is my line item - it returns 'meeting times'. However, there are some cases in my DB where the meeting time is not known and the field is null. I'm wondering if I can completly remove the 'echo' on my page if the field is null?

echo "<p<b>Meetings:</b> $variable21</p>";

put it in an if statement:

if ($variable21="")
{
//do nothing
}
else
{
echo "<p<b>Meetings:</b> $variable21</p>";
}

I tried your suggestion, but it made my test run a blank field when the value was not null..
Any ideas what I should put in the parenthesis? The value is different for over 300 records..
Thanks

Another way to do the same thing:
This should be in a loop when you are querying the database for each "row" of data.

echo ($variable21 != '') ? "<p><b>Meetings:</b> $variable21</p>" : '';

;

I may be too new to understand what you are talking about.
But I inserted your suggestion and it returns the same value as before Null or not...
Do you have time to provide me w/ a little more insight?

Another way to do the same thing:
This should be in a loop when you are querying the database for each "row" of data.

echo ($variable21 != '') ? "<p><b>Meetings:</b> $variable21</p>" : '';

;

I believe ryan_vietnow meant ($variable21=="") instead of ($variable21="") . It may not fix your problem, but == is used to compare a variable to a value or to another variable. = is used to assign a value to a variable. Don't get is equal to (==) confused with equals(=). You could also try:

if(empty($variable21)){
echo "Meeting time is not yet determined. Please check again later.";
}
else{
echo "<p<b>Meetings:</b> $variable21</p>";
}

If all else fails, use strlen to check the strings length aka the number of characters in the string assigned to the variable:

if(strlen($variable21)>1){ 
echo "<p<b>Meetings:</b> $variable21</p>";
}
else{
echo "Meeting time is not yet determined. Please check again later.";
}

I may be too new to understand what you are talking about.
But I inserted your suggestion and it returns the same value as before Null or not...
Do you have time to provide me w/ a little more insight?

This

echo ($variable21 != '') ? "<p><b>Meetings:</b> $variable21</p>" : '';

is basically saying:

if ($variable21 != '') { //if $variable21 is NOT blank/empty/null... it has something in it
  echo "<p><b>Meetings:</b> $variable21</p>"; //then echo this
} else { //or else it is blank and echo nothing '';
  echo '';
}

Thanks for your time. Unfortunately, neither worked.
I'm wondering if it is because it is a date field in MySQL?

I believe ryan_vietnow meant ($variable21=="") instead of ($variable21="") . It may not fix your problem, but == is used to compare a variable to a value or to another variable. = is used to assign a value to a variable. Don't get is equal to (==) confused with equals(=). You could also try:

if(empty($variable21)){
echo "Meeting time is not yet determined. Please check again later.";
}
else{
echo "<p<b>Meetings:</b> $variable21</p>";
}

If all else fails, use strlen to check the strings length aka the number of characters in the string assigned to the variable:

if(strlen($variable21)>1){ 
echo "<p<b>Meetings:</b> $variable21</p>";
}
else{
echo "Meeting time is not yet determined. Please check again later.";
}

Thanks. Unfortunately, it didn't work....

This

echo ($variable21 != '') ? "<p><b>Meetings:</b> $variable21</p>" : '';

is basically saying:

if ($variable21 != '') { //if $variable21 is NOT blank/empty/null... it has something in it
  echo "<p><b>Meetings:</b> $variable21</p>"; //then echo this
} else { //or else it is blank and echo nothing '';
  echo '';
}

What is the output that it does give you? Just a sample of it would be nice.

Dae-Here is a screen shot of the output... hopefully it can help the first line is my code and the second line is your code. Both lines are returning the value when the value is Null...

What is the output that it does give you? Just a sample of it would be nice.

Attachments daedal.jpg 32.58 KB

Dae - I think I figured it out - its a date field in MySql and instead of having no value it actually put in "0000-00-00"

Let me play with it some more.. you may have solved my issue... hang in...
thanks

D - Thank you very much. Two days of working on this and indeed it was the MySQL settings and the fact the values were not null - they were zeros.

Now I'm just trying to make your solution work with an email field that has a null value?


echo "<a href=\"mailto:$variable12\">Click Here To Email The Lodge</a>";

D - Thank you very much. Two days of working on this and indeed it was my MySQL settings and the fact the values were not null - they were zeros.

Now I'm just trying to make your solution work with a complicated image field - when there is no image to return..

There is always a value in the 'intLodgeNumber' field, but the $imagesFolder may not have an image.... I'm trying to make the line go away if there is no image - because the various browsers want to display a 'missing image' icon -

echo "<img src='" . $imagesFolder . $row . ".jpg' /></p>";

Dae - I think I figured it out - its a date field in MySql and instead of having no value it actually put in "0000-00-00"

Let me play with it some more.. you may have solved my issue... hang in...
thanks

For date fields such as that try:

echo ($variable21 > 0 '') ? "<p><b>Meetings:</b> $variable21</p>" : '';

D - Thank you very much. Two days of working on this and indeed it was my MySQL settings and the fact the values were not null - they were zeros.

Now I'm just trying to make your solution work with a complicated image field - when there is no image to return..

There is always a value in the 'intLodgeNumber' field, but the $imagesFolder may not have an image.... I'm trying to make the line go away if there is no image - because the various browsers want to display a 'missing image' icon -

echo "<img src='" . $imagesFolder . $row . ".jpg' /></p>";

One way to do that is:

if (file_exists($imagesFolder.$row['intLodgeNumber'].".jpg")) {
  echo "<img src='" . $imagesFolder . $row['intLodgeNumber'] . ".jpg' /></p>";
} else { //just because it was on the end of your line... echo the </p> if no image
  echo "</p>";
}

Thanks D!

At first it didn't work, then it was recommended (by another forum) that I:
change your line:

if (file_exists($imagesFolder.$row['intLodgeNumber'].".jpg")) {

to:

if (file_exists($_SERVER['DOCUMENT_ROOT'].$imagesFolder.$row['intLodgeNumber'].".jpg")) {

Thank you very much!!!!


One way to do that is:

if (file_exists($imagesFolder.$row['intLodgeNumber'].".jpg")) {
  echo "<img src='" . $imagesFolder . $row['intLodgeNumber'] . ".jpg' /></p>";
} else { //just because it was on the end of your line... echo the </p> if no image
  echo "</p>";
}
This question has already been answered. Start a new discussion instead.