show image when a field value = 1

This is a discussion on show image when a field value = 1 within the PHP Language forums, part of the PHP Programming Forums category; I am trying to get a script to show a particular image when a field value = 1, otherwise it will ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-09-2008
canajien@gmail.com
 
Posts: n/a
Default show image when a field value = 1

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
Reply With Quote
  #2 (permalink)  
Old 05-09-2008
tommybiegs@gmail.com
 
Posts: n/a
Default Re: show image when a field value = 1

On May 9, 10:28*am, "canaj...@gmail.com" <canaj...@gmail.com> wrote:
> 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 )
Reply With Quote
  #3 (permalink)  
Old 05-09-2008
noname
 
Posts: n/a
Default Re: show image when a field value = 1

- 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
Reply With Quote
  #4 (permalink)  
Old 05-09-2008
Captain Paralytic
 
Posts: n/a
Default Re: show image when a field value = 1

On 9 May, 14:52, noname <n...@email.com> wrote:
> - 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'>"
Reply With Quote
  #5 (permalink)  
Old 05-09-2008
canajien@gmail.com
 
Posts: n/a
Default Re: show image when a field value = 1

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!!!
Reply With Quote
  #6 (permalink)  
Old 05-09-2008
Rik Wasmus
 
Posts: n/a
Default Re: show image when a field value = 1

tommybiegs@gmail.com wrote:
> On May 9, 10:28 am, "canaj...@gmail.com" <canaj...@gmail.com> wrote:
>> 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]
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:17 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0