PHP if else with negative and positive numbers?
Been stuck on a little problem for some time.
I'm getting float (00.00) numbers from a database. Now I want to display them with different backgrounds, depending on the value.
if($zahl > 0 && $zahl < 10) {}
is not the problem, but as soon as a number becomes negative, I don't get it displayed.
if($zahl < -10 && $zahl < -20) {}
doesn't work. I want positive numbers from
+ 0 to +20 Green background
+20 to +40 Yellow
+40 to +60 Red
Likewise, negative numbers
– 0.01 to -10 in green
– 10.01 to – 20 in yellow
and everything above -20 is shown in red.
Does anyone have an idea?
if($number < -10 && $number < -20) {}
makes no sense. You have to write
if($number < -10 && $number >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= >= -20!
should we go?
No, I can’t. If $hour=65, the second variant becomes active and the third one no longer comes to the train. You have to program clean or let it be the same… sry
Better
Otherwise you have a gap between 19.99 and 20.00. (Or, since the floats are, if it's running stupid, it's even the same value in binary representation).
Your two letzen elseifs have the same condition, because something doesn't fit.
To the problem included:
I'd solve it differently. Make an array, write in the values at which the areas adjoin/end:
Then take the values from the array and compare it with:
No, I can’t.
The range 40 to 50 is not covered at all.
You also have overlaps in the negative area
Programming has nothing to do with faith. Your code from your comment will only produce exactly two states: bg-success and big-warning
There are figures that are not achieved with the query at all. What about the 15?
♪
Thank you!