Re: Create variables with IF staements
| From: | David Otton | Date: | Wed, 13 Dec 2000 00:48:25 +0000 |
| Subject: | Re: Create variables with IF staements | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29996@lists.php.net to get a copy of this message | ||
On Tue, 12 Dec 2000 19:17:28 -0500, you wrote:
>I am trying to assign a variable from the result of an IF statement. How an
>I do this in php? I have a field called FileImageURL which houses nopic.jpg
>if no picture is there and if there is a picture it returns apicture.jpg. I
>want it to display an image called jpg.gif if there is a picture and
>blank.gif if there isn't. I want to insert the result as a variable in my
>tables as $Image. Any suggestions?
Lots of ways, depending on your personal style. There's :
<? if ($FileImageURL=='nopic.jpg') { ?>
<img src="/home/warbirds/images/blank.gif" border="0">
<? } else { ?>
<img src="/home/warbirds/images/jpg.gif" border="0">
<? } ?>
or
<?
if ($FileImageURL=='nopic.jpg')
$Image = "/home/warbirds/images/blank.gif";
else
$Image = "/home/warbirds/images/jpg.gif";
?>
<img src="<?echo $Image?>" border="0">
or
if($FileImageURL=='nopic.jpg') {
echo '<img src="/home/warbirds/images/blank.gif" border="0">';
} else {
echo '<img src="/home/warbirds/images/jpg.gif" border="0">';
}
Plus, I'm sure, half a dozen variations on the theme.
djo