Posted by Pedro Graca on 10/30/06 20:17
["Followup-To:" header set to comp.lang.php.]
bokke wrote:
> I have a page that has several stories that run on it from a mysql
> database. Right now I use this code:
> <img src="Images/NewsPics/<?php echo $row["id"];?>.jpg" border="1">
|-------- HTML --------||------- PHP --------||--- HTML ----|
> to display the image.
>
> BUT I have added a column to the database with 1 or 2 (1=has pic, 2=no
> pic). I would like to use an IF STATEMENT
The only part of your code above that is PHP if the bit with the
filename. You need to make the PHP bigger.
<?php
echo '<img src="Images/NewsPics/'; // previous HTML
echo $row["id"]; // previous PHP
echo '.jpg" border="1">'; // previous HTML
?>
> <?php
> if (<?php echo $row["PicNumber"];?> == "2") {
> echo "";
> } else {
> echo "<img src="Images/NewsPics/<?php echo $row["id"];?>.jpg"
> border="1">";
> }
> ?>
and make your IF STATEMENT encompass all of the image
<?php // This snippet is incomplete. It does not 'work'
if ( /* something here */ ) {
echo '<img src="Images/NewsPics/';
echo $row["id"];
echo '.jpg" border="1">';
}
?>
> But I can't seem to embed the <?php echo $row["PicNumber"];?> within
> the PHP statement.
You can't embed PHP within PHP. All the code above is PHP right now.
There is no need to "reenter" PHP mode.
<?php
if ($row["PicNumber"] == 1) {
echo '<img src="Images/NewsPics/';
echo $row["id"];
echo '.jpg" border="1">';
} else {
// no <img ...> written to the browser
}
?>
> Thanks
You're very welcome. Hope this helps.
--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Navigation:
[Reply to this message]
|