SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if isset problem

    I'm using this code to check if a variable has a value and then do one of two things

    PHP Code:
     if(isset($pic)) { 
        echo(
    "<a href="edit_composer.php?id=$id" class=\"alt\"><img src="composers/$pic" alt=\"picture\" border=\"0\"></img></a><br />");
      } else {
      echo(
    "<a href="edit_composer.php?id=$id" class=\"alt\"><img src=""\"composers/photonotavailable.gif\" alt=\"picture\" border=\"0\"></img></a><br />");
      } 
    The variable $pic is coming from a database query. If a value is there the picture gets displayed, but if there is no value ($pic is empty) the "photonotavailable.gif" is NOT displayed. If I view the source in such a case, I see the relevant line is
    <img src="composers/" alt="picture" border="0"></img>
    I don't see the problem. Help? Thanks.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of using isset, try this
    PHP Code:
    if ($pic != '')
    {
        
    //show pic
    }
    else
    {
        
    //show not available pic


  3. #3
    SitePoint Zealot LiamW's Avatar
    Join Date
    Mar 2003
    Location
    Hamilton, Ontario
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change isset to !empty

    isset returns true if the variable is set, even if the value is blank.

  4. #4
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Datune and LiamW! That fixed it.


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
  •