Results 1 to 2 of 2

Thread: Image Display "IF"

  1. #1
    Join Date
    Apr 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Image Display "IF"

    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 Code:
    <?php if ($row_Recordset1['photo'] == null) echo ""?>
    Her is the image one I used
    PHP Code:
    <?php if ($row_Recordset1['photo'] == not null) echo "<img src=$rowRecordet1['photo']";?>
    Last edited by dayze_day; 04-12-2005 at 02:06 PM.

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by dayze_day
    PHP Code:
    <?php if ($row_Recordset1['photo'] == null) echo ""?>
    Why output an empty string? Seems odd to me.

    PHP Code:
    <?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 Code:
    <?php
      
    if($row_Recordset1['photo'] != null) {
        echo 
    "<img alt=\"\" src=\"{$row_Recordset1['photo']}\">";
      }
    ?>
    Hope that helps,
    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •