You are here: Re: Retrieving an Image if Condition Not Met « PHP Programming Language « IT news, forums, messages
Re: Retrieving an Image if Condition Not Met

Posted by Sandman on 05/21/06 20:44

In article <1148227958.075856.11750@i40g2000cwc.googlegroups.com>,
"Pete" <capetree@gmail.com> wrote:

> I'm sure the answer is simple, but the solution is eluding me-I'm
> not too good at the particulars of scripting. Maybe someone can point
> me on the right path...
>
> Here is the problem:
>
> I have a string of php code that retrieves an image, in this case, an
> image of a book cover from Amazon.com. This works perfectly well,
> unless, there isn't an image of the book on Amazon's server. When
> there's no image, a blank hole appears on the final page. What I
> would like to happen is, if the variable for the image isn't met
> (i.e. no book cover image), a "No Image" image, from my server,
> will load in its place.
>
> Here is the code that retrieves the image:
>
> <img border="0" src=<? echo $i['ImageUrlSmall'];?>>
>
> Is there a way to include a command that will retrieve an image from
> http://www.mysite.com/images/noimage.gif if the first condition is not
> met?
>
> If anyone can help me, I'd be grateful.
>
> --Pete

<?
$image = $i['ImageUrlSmall'] ? $i['ImageUrlSmall'] : "noimage.gif";
?>
<img src="<?=$image ?>" />

Cleaned it up so it's easier to read. You can do it this way as well:

<img border="0" src="<? echo $i['ImageUrlSmall'] ? $i['ImageUrlSmall']
: "noimage.gif";?>">


--
Sandman[.net]

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация