Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    228
    Thanks
    45
    Thanked 3 Times in 3 Posts

    Triple if statement

    Can figure this out..

    I want to show 1 of 3 images.


    if 1 does not exist try this...

    if 2 does not exist then use the default image?...

    I can get 2 to work but not 3.
    PHP Code:
    if (file_exists($img)) {
    //    echo "The file $img exists";
    echo "<img src=\"../carimages/$stockno.jpg\" height=\"120\" width=\"160\" class=\"carimg\">";
    } else {

    //    echo "The file $img does not exist";
    echo "<img src=\"../carimages/camerashy.jpg\" height=\"120\" width=\"160\" class=\"carimg\">";

    Thanks in advance..


    Slayer.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Use either an elseif or nest an if/else within the else. Alternatively, you can use a ternary operator, but I don't usually recommend that for nested functionality as PHP seems to evaluate it oddly using the left association instead of the right as C uses.

  • Users who have thanked Fou-Lu for this post:

    SlayerACC (01-06-2013)

  • #3
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    228
    Thanks
    45
    Thanked 3 Times in 3 Posts
    Dang...


    Thanks for that...


    Sometimes you just can see it...


    Anyway... got it going...


    Thanks Fou-Lu

    Slayer.

  • #4
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts
    i think ,can i use this method for three condition
    PHP Code:
    <?php

    if (file_exists($img))
      {
     echo 
    "The file $img exists"
      }
    elseif (
    file_exists($img1))
      {
      echo 
    "The file $img1 exists";
      }
    else
      {
      echo 
    "The file $img  & $img1 does not exist"
      }
    ?>

  • Users who have thanked minkoko for this post:

    SlayerACC (01-07-2013)

  • #5
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    would work fine
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com


  •  

    Posting Permissions

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