Forum Moderators: coopster

Message Too Old, No Replies

IF question in dreamweaver

         

transmutated

9:13 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



I am trying to set up a page that gets a dump from a database. One of the fields is capable of 2 values, 0 and 1. What I am trying to do is set it up to when a value comes in it displays one of two pictures. Essentially, what I am doing is this:

<? $status = recordsetname(field);
?>

<?
if ($status == "0" {
echo "<img src="img/status0.gif" />";
} else {
echo "<img src="img/status1.gif" />";
}
?>

I am unsure of using HTML in an echo command. I dont know if it works or not. But that is essentially what i have on my page. When I go to load it in a browser... nothing comes up. But I have tried every thing. Its probably something dumb with a space or a quotation. But if there is a better way to do this... all help is appreciated. Thanks in advance.

jatar_k

9:58 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hard for me to say whether this bit works as it is likely a custom function

<? $status = recordsetname(field);
?>

for the next part there are a couple of things. If $status is actually a number then you don't need quotes around the 0. You also have some quote mismatches. As you have variables to be resolved inside your img tags then just use single quotes around the outside. It is also missing a ) in your if

<?
if ($status == 0) {
echo '<img src="img/status0.gif" />';
} else {
echo '<img src="img/status1.gif" />';
}
?>

about quoting strings
[php.net...]

inveni0

10:45 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



Try this syntax:

<? $status = $row_DataBase['columnname'];
?>

<?
if ($status == "0") {
echo "<img src='img/status0.gif'>";
} else {
echo "<img src='img/status1.gif'>";
}
?>

You had a couple typos, and you need to use single quotes when echoing HTML (or escape them with \)