Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Dynamic image displays depending on yes / no value

Community Beginner ,
Sep 26, 2011 Sep 26, 2011

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 !!!!

TOPICS
Server side applications
757
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 29, 2011 Sep 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.

Translate
LEGEND ,
Sep 26, 2011 Sep 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" />

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 27, 2011 Sep 27, 2011

nooob....

sorry, it´s not working.

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

result showing up:

Parse error:  syntax error, unexpected '<'

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 29, 2011 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 08, 2011 Oct 08, 2011

Many thnaks, now it´s working fine for me.

(the file extension writen with Dreamweaver was set to html)

Example: http://mediaconsults.de/1test/steckertest.phn

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 10, 2011 Oct 10, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 26, 2011 Sep 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 ...)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines