Copy link to clipboard
Copied
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 !!!!
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.
Copy link to clipboard
Copied
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" />
Copy link to clipboard
Copied
nooob....
sorry, it´s not working.
i´ve tried it in different combinations....
result showing up:
Parse error: syntax error, unexpected '<'
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Many thnaks, now it´s working fine for me.
(the file extension writen with Dreamweaver was set to html)
Copy link to clipboard
Copied
Presumably you mean this -
http://mediaconsults.de/1test/steckertest.php
And it's not clear what that is going to show me. Looking at the code on the page -
<html>
<head>
<title>Unbenanntes Dokument</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body background="test%20png.png">
<div id="Layer1" style="position:absolute; left:1290px; top:246px; width:95px; height:112px; z-index:1"><img src="stecker_off.png" alt="no"height="101" width="71" /></div>
</body>
</html>
I would advise you the following:
1. Put a valid and complete doctype on that page!
2. Get rid of the resize if NN4 javascript - it hasn't been needed for nearly a decade.
3. Fix your image code (note the missing space after "no"!
4. 1290px is way too wide unless you want lots of people scrolling right to see things.
Copy link to clipboard
Copied
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 ...)