Skip to main content
Participant
September 26, 2011
Answered

Dynamic image displays depending on yes / no value

  • September 26, 2011
  • 2 replies
  • 874 views

Dynamic image displays depending on yes / no value    

I´d like to have a image showing, depending on a specific value (y/n)

..sorry need some help.

I can´t get it workin.....

<img <?php $status="n";

if ($status == "y") {

  echo 'src="stecker_on.png" alt="yes"';

} else {

  echo 'src="stecker_off.png" alt="no"';

} ?> height="71" width="101" />

The image ist not showing... ideas ?

All I get ist some text showing:

  height="71" width="101" />

MANY THANKS !!!!

This topic has been closed for replies.
Correct answer MurraySummers

That error could only mean that you didn't implement my suggestion correctly, or that there is a pre-existing error on your page.  The code I gave you is correct.

2 replies

Participant
September 26, 2011

ok, i´ll give it a try this evening.

(I set the $status for testing to n - later i´ll read out the status of my light swithes in my home automation system... depending on the status I´ll show an image with lights on ...)

MurraySummers
Inspiring
September 26, 2011

In the code that you show above, $status is explicitly set to "n" at the beginning (<?php $status="n";), so the conditional will always evaluate to the 'else' part - is that what you want?

All I get ist some text showing:

  height="71" width="101" />

That's what you see on the page - those words in readable text? Try this -

<img src="stecker_<?php $status="n"; echo ($status == "y")?'on':'off'; ?>.png" alt="<?php echo $status=="y"?'yes':'no'; ?>" height="71" width="101" />

Participant
September 27, 2011

nooob....

sorry, it´s not working.

i´ve tried it in different combinations....

result showing up:

Parse error:  syntax error, unexpected '<'

MurraySummers
MurraySummersCorrect answer
Inspiring
September 29, 2011

That error could only mean that you didn't implement my suggestion correctly, or that there is a pre-existing error on your page.  The code I gave you is correct.