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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 ) |
|
|||
|
- 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 |
|
|||
|
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'>" |
|
|||
|
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!!! |
|
|||
|
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] |