By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

show image when a field value = 1

P: n/a
I am trying to get a script to show a particular image when a field
value = 1, otherwise it will show something else, and this is what I
came up with:

$i=0;
while ($i < $num) {

$name=mysql_result($result,$i,"name");
$date=mysql_result($result,$i,"date");
$status=mysql_result($result,$i,"status");

echo "<b>$name</b>
<br><b>$date</b><br";

if (status == 1) {
echo <img src='../images/yes.jpg'>
} else {
echo <img src='../images/no.jpg'>
}

;

$i++;
}
and nothing shows up, if I remove the if clause then I get the text
showing name and date. What am I doing wrong, aside from not really
knowing how to program php?

Thanks
Jun 2 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On May 9, 10:28*am, "canaj...@gmail.com" <canaj...@gmail.comwrote:
I am trying to get a script to show a particular image when a field
value = 1, otherwise it will show something else, and this is what I
came up with:

$i=0;
while ($i < $num) {

$name=mysql_result($result,$i,"name");
$date=mysql_result($result,$i,"date");
$status=mysql_result($result,$i,"status");

echo "<b>$name</b>
<br><b>$date</b><br";

if (status == 1) {
* * * * * * * * * echo <img src='../images/yes.jpg'>
* * * * * * * * *} else {
* * * * * * * * * echo <img src='../images/no.jpg'>
* * * * * * * * *}

;

$i++;

}

and nothing shows up, if I remove the if clause then I get the text
showing name and date. *What am I doing wrong, aside from not really
knowing how to program php?

Thanks
if ( status == 1 )

is not the same as

if ( $status == 1 )
Jun 2 '08 #2

P: n/a
- missing $ on status
- missing double quotes on echo lines and semicolon at the end
- you have an extra semicolon there as well

you can download a manual here
http://www.php.net/download-docs.php
and give it a try
Jun 2 '08 #3

P: n/a
On 9 May, 14:52, noname <n...@email.comwrote:
- missing $ on status
- missing double quotes on echo lines and semicolon at the end
- you have an extra semicolon there as well

you can download a manual herehttp://www.php.net/download-docs.php
and give it a try
And
echo <img src='../images/yes.jpg'>
is not the same as
echo "<img src='../images/yes.jpg'>"
Jun 2 '08 #4

P: n/a
Thanks guys, the missing dollar sign was just an error on my part, it
slipped through. As for the semi colon thing I thought it was enough
to place it at the end of the if statement, but now I know better, it
has to go at the end of each echo within the if statement

if ($status == 1) {
echo "<img src=\"../images/yes.jpg\">";
} else {
echo "<img src=\"../images/no.jpg\">";
}

and now it works!!!
Jun 2 '08 #5

P: n/a
to********@gmail.com wrote:
On May 9, 10:28 am, "canaj...@gmail.com" <canaj...@gmail.comwrote:
>I am trying to get a script to show a particular image when a field
value = 1, otherwise it will show something else, and this is what I
came up with:

$i=0;
while ($i < $num) {

$name=mysql_result($result,$i,"name");
$date=mysql_result($result,$i,"date");
$status=mysql_result($result,$i,"status");

echo "<b>$name</b>
<br><b>$date</b><br";

if (status == 1) {
echo <img src='../images/yes.jpg'>
} else {
echo <img src='../images/no.jpg'>
}

;

$i++;

}

and nothing shows up, if I remove the if clause then I get the text
showing name and date. What am I doing wrong, aside from not really
knowing how to program php?

Thanks

if ( status == 1 )

is not the same as

if ( $status == 1 )
Indeed. At the OP: set error_reporting(E_ALL | E_STRICT) while
developing, and enable display_errors. It would probably have told you
there is no constant 'status' defined.

--
Rik Wasmus
[SPAM]
Now looking for some smaller projects to work on to fund a bigger one
with delayed pay. If interested, mail rik at rwasmus.nl
[/SPAM]
Jun 2 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.