PDA

View Full Version : Image Display "IF"



dayze_day
04-12-2005, 07:11 AM
I am trying to get an image field to NOT display if a image is NOT present. I managed to get this to work displaying the path but I can not get it to work with the image. It gives me a string error. I have tried it a few ways and same problem. Please HELP!

Here is the path one I used

<?php if ($row_Recordset1['photo'] == null) echo ""; ?>

Her is the image one I used

<?php if ($row_Recordset1['photo'] == not null) echo "<img src=$rowRecordet1['photo']";?>

mwinter
04-13-2005, 06:06 PM
<?php if ($row_Recordset1['photo'] == null) echo ""; ?>Why output an empty string? Seems odd to me.



<?php if ($row_Recordset1['photo'] == not null) echo "<img src=$rowRecordet1['photo']";?>If you want to check if the variable is not equal to null, then use the != operator.

By the way, you should output quotes around that variable, you've omitted the closing delimiter for the img element (>), and you should also send an alt attribute, even if it's just an empty string.


<?php
if($row_Recordset1['photo'] != null) {
echo "<img alt=\"\" src=\"{$row_Recordset1['photo']}\">";
}
?>Hope that helps,
Mike