Author Topic: Color-Changing Temperature/Humidex/Wind Guest etc  (Read 3363 times)

Offline [David]

  • Jr. Member
  • **
  • Posts: 13
    • Meteo Catanzaro
Color-Changing Temperature/Humidex/Wind Guest etc
« on: January 25, 2013, 04:30:23 AM »
Hi there, pleeeeeeeeeeeeeeeeease I really need an help in Color-changing temperature!!!  :(

I tried to follow these istructions http://weatherbyyou.com/diy_php_and_cumulus.php but it gives me an error! I need to automatically change my $temp color if > or < of temperature value given by #temp from Cumulus! I also need the same color-changing with humidex and other values such as barometer, wind guest etc etc.

Can someone help me?????

Thank you!

David

Offline Mr.Meteo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1120
    • http://www.meteostours.ca
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #1 on: January 25, 2013, 11:41:41 AM »
Hi Dadiv,

As you are using a php template, pages aren't processed, then <#temp>
is not available in your page!! Data are already in Php, then use it directly, like this:

if ($temp > 30) ....

Hope this help!

Regards,
Jacques
Please, consider supporting this site 

Offline [David]

  • Jr. Member
  • **
  • Posts: 13
    • Meteo Catanzaro
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #2 on: January 26, 2013, 05:21:30 AM »
God bless you Mister!!! Sorry but I`m not so much smart with php...

Following those instructions above (I mean those you find here http://weatherbyyou.com/diy_php_and_cumulus.php) and replacing them like this :

Code: [Select]
<?php
   
if ($temp 20)      // If temperature above 20°C
   
{
      
$temp_color '#FF0000'// Write in Red.
   
}
    elseif (
$temp 0)  // If temperature below zero
   
{
      
$temp_color '#0000FF'// Write with Blue.
   
}
    else                
// If temperature above 0, but below 30.
   
{
      
$temp_color '#FFFFFF'// Write in White.
   
}
?>


Nothing has changed  :( I`m really sad `cuz I need to find a solution with Temperature, Humidex, Wind values...I need to auto change their color if < or > :(

 ^-^ ^-^ ^-^ ^-^ ^-^ ^-^ ^-^ ^-^ ^-^ ^-^ ^-^ ^-^ ^-^

I`m sure I`m doing something wrong...and maybe you told me an easy way to fix it but...Sorry I didn`t understand what to change if not <#temp>

Offline Mr.Meteo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1120
    • http://www.meteostours.ca
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #3 on: January 26, 2013, 08:36:44 AM »
Hi David,

Then, your "color selection" (if) is ok, and you have in the $temp_color variable
the right color to represent the temperature. What you need is a way to include it
in your text, example on the site is basic for a html template with a php "injection".
So, if I take example of your index page, like you have seen data are in index_txt.php:

<?php echo '<td>'.$now_temp.'</td><td>'.$temp.' '.$tempunit.'</td>...

Then, "wrap" the $temp with this "<span>":

<?php echo '<td>'.$now_temp.'</td><td><span style="color:'.$temp_color.'">'.$temp.'</span> '.$tempunit.'</td>...

So it is the same thing for all other that you want to colorize! We have to apply
a style, but since we are in the middle of a line, we have nothing to put our color
to, then we use a "<span>... </span>" which have no effect on text, but we could also
choose that we put that number in bold and by that way, colorize our bold, all that just
by changing word "span", by "strong" like this:

<strong style="color:'.$temp_color.'">'.$temp.'</strong>
So, many way to "play" with it. So, have fun!!  :D

Regards,
Jacques
Please, consider supporting this site 

Offline [David]

  • Jr. Member
  • **
  • Posts: 13
    • Meteo Catanzaro
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #4 on: January 26, 2013, 09:15:49 AM »
Oh MY GOD Misteeeeeeeeeeeeeeer!!!!!!!!!!!!!!!!!! IT JUST WORKS!!!  :-* :)) :-X

Can`t believe it! You saved me...Now I`m gonna play with this 8)

The only thing I notice, is that I must set

Code: [Select]
<?php
   
if ($VALUE X)      // If temperature above VALUE
   
{
      
$temp_color '#FF0000'// Write in Red.
   
}
    elseif (
$VALUE X)  // If temperature below VALUE
   
{
      
$temp_color '#0000FF'// Write with Blue.
   
}
    else               
// If temperature above VALUE, but below VALUE
   
{
      
$temp_color '#FFB0B0'// Write in Normal.
   
}
?>


for EACH one of value I wanna color or blink or else...For example I must write this one for Humidex

Code: [Select]
<?php
   
if ($humidex 70)      // If humidex above 70%
   
{
      
$temp_color '#FF0000'// Write in Red.
   
}
    elseif (
$humidex 40)  // If humidex below 40%
   
{
      
$temp_color '#0000FF'// Write with Blue.
   
}
    else               
// If temperature above 40, but below 70.
   
{
      
$temp_color '#FFB0B0'// Write in Normal.
   
}
?>


...then <span style="color:'.$temp_color.'">'.$humidex.'</span> '.$tempunit.'</td> ????? Am I right??! And what if I wanna BLINK or BOLD so???

<blink style=...> ?????????????
<bold style=...> ?????????????

Without adding anything to the php code above?! Doesn't it blink or bold anytime in this way even if VALUES aren`t ABOVE or BELOW the value I set???

Hope you understand what I said  :-X ...And MAN...THANK YOU SOOOOOOOOOO MUCH!!!!
« Last Edit: January 26, 2013, 09:19:30 AM by [David] »

Offline Mr.Meteo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1120
    • http://www.meteostours.ca
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #5 on: January 26, 2013, 09:44:40 AM »
Hi David,

Php is opening a whole new world of possibilities, but as you said, there is a bunch
of lines just to change the color, and this is normal!! We have to define things
all over again! (As I don't want to complicate things with php "procedures")

As you already discovered, php is only inserting html, php doesn't really exist
because the final result is a good old plain html file, what we've done with all
those lines are finally "translated" to <span style="color:#FF0000">33,9</span>.
As you see what I have done with that is just inserting an inline css style, into
a non-effect tag (the <span style ="..." and choosen in advance that the only
style that I will use is color... so, I inserted the color: and having to supply
only the color "number"...

But if I want to open the style option widely, I could do something like this:

<span style="'.$MyStyle.'"...

Now, as you understant with $MyStyle variable, I don't want to only change temperature
color ($temp_color), but do my own styling, and not being limited in any way!! Last thing
to do is to revise my condition (if) accordingly, example:

if ($temp > 30)
{
   $MyStyle = 'color:#FF0000; font-size: 120%; font-weight: bold';  \\ And so on as long as you want!!
}

As you see, like that all is open... it's like a "brunch"... all you can eat!!!  :))

Let's go and give your imagination a ride!!

Cheers,
Jacques
Please, consider supporting this site 

Offline [David]

  • Jr. Member
  • **
  • Posts: 13
    • Meteo Catanzaro
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #6 on: January 26, 2013, 10:12:02 AM »
Clear!!!! I`m just trying to blink, bold and colorate the HUMIDEX value if ABOVE 50

So I just did this one

Code: [Select]
<?php
   
if ($hum 50)      // If humidex above 70%
   
{
      
$MyStyle 'color:#FF0000; blink; font-weight:bold'// Write in Red.
   
}
    elseif (
$hum 40)  // If humidex below 40%
   
{
      
$MyStyle 'color:#0000FF'blinkfont-weight:bold'; // Write with Blue.
   }
    else               // If humidex above 40, but below 70.
   {
      $MyStyle = '
color:#FFB0B0'; // Write in Normal.
   
}
?>


...then I edit <span style="'.$MyStyle.'">'.$hum.'</span> but it just gives me and error on line 32 which could be identified on PHP Code above...Strange thing `cuz it seems everything ok, doesn`t it????

Thank you again you`re showing me A WORLD  :-* :-* :-* :-* :-*

EDIT : First error find, it was an ' after blue color in php code...
Now it gives me another error Parse error: syntax error, unexpected '<' in /membri/czmeteo/index_txt.php on line 58

which it should be here : <?php echo '<td>'.$Tr_avgtemp.'</td><td>'.$avgtemp.' '.$tempunit.'</td><td>'.$now_hum.'</td><td><span style="'.$MyStyle.'">'.$hum.'</span>'%</td>'; ?>
<tr class="td_data">


EDIT 2 : FIXED!!!! But it just doesn`t blink :( I just wanna let it blink only if valus is above (for example) 50, so I`ve written in php code = $MyStyle = 'color:#0000FF'; blink; font-weight:bold';

EDIT 3 : FIXED by adding text-decoration: blink THANK YOUUUUUUUUUUUUUUUU

P.s.
Doesn anyone know how to blink with every browser instead of just Firefox!?
« Last Edit: January 26, 2013, 10:32:07 AM by [David] »

Offline Mr.Meteo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1120
    • http://www.meteostours.ca
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #7 on: January 26, 2013, 11:08:59 AM »
Hi David,
Things are gooing good! But that's it for the good news!  >:(

Blink is a pretty old technique, and since too many poeple abuse of its use,
it is now abandonned! Think of all those sites with so many  blinking things
that it was near impossible to read their content!

Then as you can see in that short text, blink is now not supported by majority
of browser: http://www.bentoweb.org/ts/XHTML1_TestSuite2/metadata/sc2.2.2_l2_003
It's now a "waste of taste" to use blinking and if you want to use it despite all,
you have to work harder and add javascript to your page... you could see
an example here: http://help.dottoro.com/lhcpjgva.php

Hope this help,
Jacques
Please, consider supporting this site 

Offline [David]

  • Jr. Member
  • **
  • Posts: 13
    • Meteo Catanzaro
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #8 on: January 26, 2013, 11:22:56 AM »
Yeah I`ve seen about that java script...By the way, I`m compiling each php code for every value I want to colorize. I did it with Temp, Humidex and they work fine (just set $temp_color and $hum_color).

Once arrived to $press_color and generate php (as you can see below)

Code: [Select]
<?php
   
if ($temp 20)      // If temperature above 20°C
   
{
      
$temp_color '#FF0000; font-weight:bold'// Write in Red.
   
}
    elseif (
$temp 10)  // If temperature below 10°C
   
{
      
$temp_color '#0000FF; font-weight:bold'// Write with Blue.
   
}
    else               
// If temperature above 10, but below 20.
   
{
      
$temp_color '#black'// Write in Normal.
   
}
?>


<?php
   
if ($hum 70)      // If humidex above 70%
   
{
      
$Stile 'color:#FF0000; text-decoration: blink; font-weight:bold'// Write in Red.
   
}
    elseif (
$hum 40)  // If humidex below 40%
   
{
      
$Stile 'color:#0000FF; text-decoration: blink; font-weight:bold'// Write with Blue.
   
}
    else               
// If humidex above 40, but below 70.
   
{
      
$Stile 'color:#black'// Write in Normal.
   
}
?>


<?php
   
if ($press 1016)      // If pressure above 1016
   
{
      
$press_color 'color:#green; font-weight:bold'// Write in green
   
}
      elseif (
$press 1000)  // If pressure below 1000
   
{
      
$press_color 'color:#red; text-decoration: blink; font-weight:bold'// Write with red
   
}
    else               
// If humidex above 1000, but below 1016.
   
{
      
$press_color 'color:#green'// Write in Normal.
   
}
?>


and once set the span like this :

Code: [Select]
<?php echo '<td>'.$Tr_press.'</td><td><span style="'.$press_color.'">'.$press.'</span> '.$pressunit.'</td><td>'.$Tr_presstrend.'</td><td>'.$presstrendval.' '.$pressunit.'/hr</td>'?>

I still can see pressure at 1006 without any color  :P :P :P ... :o Now I`m wondering whyyyyyyyyy  >:D

P.s.:
It`s really nice to see temperature value blue colored it below 10° and red if above 20°  :-*

Offline Mr.Meteo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1120
    • http://www.meteostours.ca
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #9 on: January 26, 2013, 11:53:23 AM »
Hi David,

It is normal that the color don't change as the condition is not meeted.
Your condition is not triggered: 1016 is not greather then 1016!!!

To test, try to put your condition a little farther from your current reading!  ;)

Regards,
Jacques
Please, consider supporting this site 

Offline [David]

  • Jr. Member
  • **
  • Posts: 13
    • Meteo Catanzaro
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #10 on: January 27, 2013, 04:39:37 AM »
mhmhmhm :-X fixed that yesterday...I set values color GREEN if between 1000 and 1013, BLUE if above 1013 and RED if below 1000.

Everything seems working now :-\ BUT (coundn`t there be a "but"?)...I`m having some troubles with pressure trend value and temperature trend value...maybe just because there`s a + or a - sign before the value (for example +1,1 C° or - 0,3 hPa/hr).

I`m using the same php code for these values

Code: [Select]
<?php
   
if ($presstrendval >= 0.1)      // If pressure trend +
   
{
      
$presstr_color 'color:#1FA531; font-weight:bold'// Write in green
   
}
      elseif (
$presstrendval <= 0.1)  // If pressure trend -
   
{
      
$presstr_color 'color:#FA0919; text-decoration: blink; font-weight:bold'// Write with red
   
}
else               
// Otherwise black.
   
{
      
$presstr_color 'color: #black'// Write in Normal.
   
}
?>


I had to set it >= and <= but even if I only writ > and < results don`t change. I think I`m doing everything right now and I suppose it could be a "+" or "-" issue...

Can you suggest me a solution for only these two value?

I know I`m abusing of you  :'(

EDIT :
I found a BAD BAD BAD "bug" in way to color values such as "trends"...Just because I can set colors if a value is ABOVE or BELOWE what I choose, BUT...PHP doesn`t see the NEGATIVE or POSITIVE sign such as those above (+ and -).

So, if I set $temptrend GREEN if ABOVE 1 and RED if BELOW 1, it understands +0,8 as RED!!! Because it`s a number BELOW 1 anyway!!! It doesn`t interpret it as positive as it is...In this way, I could even see a -2,3 as GREEN instead of RED!!! Because it`s ABOVE 1 anyway :'( :'( :'( :'( :'( :'( :'( :'( :'( :'(

The same thing appears to $presstrend too...

How can I fix it?! :'( :'( :'( :'( :'( :'( :'( :'( :'( :'(  How can I let it interpret values with - as BELOW 1 and values with or without + as ABOVE 1 ?!?!

:'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'(
« Last Edit: January 27, 2013, 05:31:50 AM by [David] »

Offline Mr.Meteo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1120
    • http://www.meteostours.ca
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #11 on: January 27, 2013, 08:06:55 AM »
Hi David,
Are you trying to do a coloring book with your site (joke)????  :))

Sometime it is difficult to play with numbers, as they are not represented
on regular way! Then we have to force thing. Php is a good language as
he doesn't force thing and is convivial with simple conversion. Then, you
could try to convert it with a simple addition, like this:

$temptrend = $temptrend + 0;

Or we could take it as a string and play with its sign, like this:

if ($temptrend[0] === '+').... put the red
So these could help you... but next color question, I'll provide coloring pen!!  :))

Jack the Joker!  :D
Please, consider supporting this site 

Offline [David]

  • Jr. Member
  • **
  • Posts: 13
    • Meteo Catanzaro
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #12 on: January 27, 2013, 12:26:48 PM »
 8) 8) 8) 8) 8) 8) 8) 8) 8) DID IT ALL!!! Everything works great...Just finished right now. I coloured :

Temp (if below 10 blue if above 22 red otherwise simply black)
AppTemp (if below 10 blue if above 22 red otherwise simply black)
All Trends - Temp and Press, and DewPoint (if - 0 red if + 0 green)
Wind, Guest, Beaufort etc (if F0 one, if F1 another, if F2 another one etc etc)
and much more...  :-\ :-\ :-\ :-\ :-\

I`m pretty happy now I don`t even know HOW COULD I THANK YOU Mr.Meteo!!!!!!!!!!!! You SAVED ME  :-*

Best best best best regards..

David

Offline Mr.Meteo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1120
    • http://www.meteostours.ca
Re: Color-Changing Temperature/Humidex/Wind Guest etc
« Reply #13 on: January 27, 2013, 03:34:06 PM »
Hi David,
You are very welcome!! 8)
Happy that you customize it to all that you want!!  :D

Hope you lot of fun with your template!!

Regards,
Jacques
Please, consider supporting this site