Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4021) - 04 May 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Php - New varaiable

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
beelzebubs
Posts: 62
Joined: Sun 04 Oct 2009 10:18 pm
Weather Station: Davis VP2
Operating System: Windows 7
Location: Sweden
Contact:

Php - New varaiable

Post by beelzebubs »

I'm try to get a picture to show up when a certain color is shown, but how do I convert the results to a new variable?
I don't want to print it out right away, I want it to end up in a new variable that I can use later.

Let say it all end up with the variable $test
If the color is #ffffff the variable $test will show the picture error.gif
But if the color is #fe0104 the variable $test will show the picture varning3.gif instead.

Code: Select all

if ($WarnColor=="#ffffff")
  {
  echo "<img src='Varningar/error.gif'>";
  }
elseif ($WarnColor=="#29d660")
  {
  echo "img src='Varningar/ingen_varning.gif'";
  }
elseif ($WarnColor=="#ffff00")
  {
  echo "<img src='Varningar/varning1.gif'>";
  }
elseif ($WarnColor=="#fecb31")
  {
  echo "<img src='Varningar/varning2.gif'>";
  }
elseif ($WarnColor=="#fe0104")
  {
  echo "<img src='Varningar/varning3.gif'>";
  }
else
  {
  echo "Something has gone terribly wrong - time to shut down";
  }
User avatar
steve
Cumulus Author
Posts: 26701
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Php - New varaiable

Post by steve »

Replace "echo" with "$test=", then later do "echo $test".
Steve
User avatar
beelzebubs
Posts: 62
Joined: Sun 04 Oct 2009 10:18 pm
Weather Station: Davis VP2
Operating System: Windows 7
Location: Sweden
Contact:

Re: Php - New varaiable

Post by beelzebubs »

Thanks Steve, and have a happy new year!
Regards Kenneth
Karv
Posts: 40
Joined: Sun 16 Dec 2012 11:19 pm
Weather Station: WH-1080
Operating System: Windows XP / 7, Ubuntu, Centos
Location: South Gloucestershire

Re: Php - New varaiable

Post by Karv »

as a side note, use of switch() is probably better suited to this.

Code: Select all

switch($WarnColor){
    case "#ffffff" :
        $test='Varningar/error.gif';
    break;

    case "#29d660" : 
        $test = 'Varningar/ingen_varning.gif';
    break;
(... etc etc ...)

    case #fecb31" : // you can have multiples to give one result:
    case #gecb32" :
    case #hecb33" : 
        $test = 'Varningar/varning3.gif';
    break;

    default :  // this is for when nothing above matches
        $test = 'very_wrong.gif';
    break;
}
Post Reply