Page 1 of 1
How do I transfer text to a logical value - with PHP
Posted: Thu 23 Feb 2012 10:16 pm
by beelzebubs
How do I transfer the text in the tag $temptrendenglish to a logical value?
I want:
Rising to 1
Falling to -1
and Steady to 0
So if the trends says falling I could have 1 in stead.
My idea is to check whats the value of the $temptrendenglish is an then with a new tag have a logical value out instead.
Say if $temptrendenglish is Rising then the tag $loicaltemptrends says it is 1 instead.
I need a logical value in stead of a text.
I think it would bee possible to do this with php but i don't now how and i haven't find any useful on the www.
So if some one will give me a helping hand i would be thankfull.
/Kenneth
Re: How do I transfer text to a logical value - with PHP
Posted: Thu 23 Feb 2012 11:32 pm
by beteljuice
Why use $temptrendenglish ?
There a numeric trend value you can apply your logic to and also apply your own ideas of 'steady', and various 'degrees' of rising / falling.
Re: How do I transfer text to a logical value - with PHP
Posted: Fri 24 Feb 2012 10:02 am
by beelzebubs
beteljuice you should never ask why
I no pro, but I do my best.
The numeric trend, these one I haven't seen maybe I was to tired.
But thanks for the tip.
I have came half the way, but I need a little help to reach the goal.
I have done like these:
Code: Select all
<?php
if ($TChangeLastHour == 0){
echo "Steady";
}
else if ($TChangeLastHour >0.01){
echo "Rising";
}
else {
echo "Falling ";
}
?>
Just to see if my idea works, and theoretical it does.
Because if I change the value of TChangeLastHour I can see the right text.
(TChangeLastHour is the same as TempChangeLastHour but with a dot instead of a comma)
But how do I close it all up?
Normally in the script I use
Code: Select all
echo' var cu_rain = '.$RCrfall.';';
so I can use a javascript call/check for the cu_rain but I really don't now how to get this to work with the if/else.
Please explain.
/Kenneth
Re: How do I transfer text to a logical value - with PHP
Posted: Fri 24 Feb 2012 12:14 pm
by beteljuice
You are practically there - although ==0 check is far too 'tight' for steady.
Rip this code apart to suit your purposes
Code: Select all
<?php
// lets do some pressure trend and storm stuff - NB: this is all hPa / mb
// Barometric Trend (3 hour) - NB. cumulus gives an hourly average of last 3 hrs
// so we need to x3 for our weather decisions
$weather_trend = $TChangeLastHour * 3;
if (($weather_trend >= -0.7) && ($weather_trend <= 0.7)) {
$pressure_trend_text = "Steady";
$p_arrow = 0; // steady
}
if (($weather_trend > 0.7) && ($weather_trend < 2.0 )) {
$pressure_trend_text = "Rising";
$p_arrow = 1; // rising
}
if ($weather_trend >= 2.0) {
$pressure_trend_text = "Rising";
$p_arrow = 1; // rising rapidly
}
if (($weather_trend < -0.7) && ($weather_trend > -2.0)) {
$pressure_trend_text = "Falling";
$p_arrow = -1; // falling
}
if ($weather_trend <= -2.0) {
$pressure_trend_text = "Falling";
$p_arrow = -1; // falling rapidly
}
if($weather_trend <= -7){ // add storm / End Of The World warning :-)
// do something interesting
}
// create js variable
echo' var cu_press_trend = '.$p_arrow.';';
?>
Note this gives you the option to have a greater 'range' of -x / 0 / +x if you wish.
For simple -1 / 0 / +1
You can shorten to something like:
Code: Select all
$weather_trend = $TChangeLastHour * 3;
if (($weather_trend >= -0.7) && ($weather_trend <= 0.7)) {
$p_arrow = 0; // steady
} elseif ($weather_trend > 0) { // already done 'steady' range check - MUST be rising
$p_arrow = 1; // rising
} else {
$p_arrow = -1; // done other checks - MUST be falling
}
// create js variable
echo' var cu_press_trend = '.$p_arrow.';';
?>
Re: How do I transfer text to a logical value - with PHP
Posted: Fri 24 Feb 2012 12:27 pm
by beelzebubs
Thanks beteljuice
I will check further into this tonight when things have cool down a little bit.
Re: How do I transfer text to a logical value - with PHP
Posted: Fri 24 Feb 2012 4:03 pm
by mcrossley
Or with just two compares:
Code: Select all
$weather_trend = $TChangeLastHour * 3;
$p_arrow = 0; // steady
if ($weather_trend >= 0.7) {
$p_arrow = 1; // rising
} else if ($weather_trend <= -0.7){
$p_arrow = -1; // falling
}
How many ways to skin a cat?

Re: How do I transfer text to a logical value - with PHP
Posted: Fri 24 Feb 2012 4:27 pm
by beteljuice
mcrossley wrote:How many ways to skin a cat?

Code: Select all
$weather_trend = $TChangeLastHour * 3;
// create js variable
echo' var cu_press_trend = ' .($weather_trend >= 0.7 ? 1 : ($weather_trend <= -0.7 ? -1 : 0)). ';';

Re: How do I transfer text to a logical value - with PHP
Posted: Fri 24 Feb 2012 4:32 pm
by mcrossley
Now you're just showing off
