Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-06-2013, 05:03 PM   PM User | #1
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
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.
SlayerACC is offline   Reply With Quote
Old 01-06-2013, 05:14 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
SlayerACC (01-06-2013)
Old 01-06-2013, 05:20 PM   PM User | #3
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
Dang...


Thanks for that...


Sometimes you just can see it...


Anyway... got it going...


Thanks Fou-Lu

Slayer.
SlayerACC is offline   Reply With Quote
Old 01-06-2013, 05:31 PM   PM User | #4
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
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"
  }
?>
__________________
Quote:
Myanmar Web Developer & Designer
http://www.cyberoot.com
minkoko is offline   Reply With Quote
Users who have thanked minkoko for this post:
SlayerACC (01-07-2013)
Old 01-07-2013, 12:49 PM   PM User | #5
hinch
Regular Coder

 
hinch's Avatar
 
Join Date: Sep 2005
Location: UK
Posts: 921
Thanks: 25
Thanked 79 Times in 79 Posts
hinch is on a distinguished road
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
hinch is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:20 PM.


Advertisement
Log in to turn off these ads.