php_admin Posted June 7, 2009 Share Posted June 7, 2009 Hello, I really need some help with solving a problem I have with a script on my site. I am not the most experienced in PHP, but I know the basics... I have a weather script on my site that updates every 2 hours to show the current weather. For example, it could say "Partly Cloudy, 17°C" on the page. I want to make the background color of this element change with the temperature of the weather. However, the temperature is a number, not a color. So how would I convert a number into how strong/dark the color is? I already made a script for the basic colors, but now I need to change the opacity based on the temperature. if($temp < 10){ $temperature_color = "green"; } else if ($temp >= 10 && $temp < 20){ $temperature_color = "yellow"; } else if ($temp >= 20 && $temp < 30){ $temperature_color = "orange"; } else { $temperature_color = "red"; } Maybe the code could be something like: if($temp < 10){ $opacity = $temp * 10; } else if ($temp >= 10 && $temp < 20){ $opacity = $temp * 5; } else if ($temp >= 20 && $temp < 30){ $opacity = $temp * 3.3; } else { $opacity = $temp * 2.5; } Any ideas on how to do this? Thank you! Any and all help is appreciated. --m Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 7, 2009 Share Posted June 7, 2009 <?php switch(true) { case $temp < 10: $temperature_color = 'green'; $opacity = $temp*10; break; case $temp < 20: $temperature_color = 'yellow'; $opacity = $temp*5; break; case $temp < 30: $temperature_color = 'orange'; $opacity = $temp*3.3; break; default: $temperature_color = 'red'; $opacity = $temp*2.5; } ?> Quote Link to comment Share on other sites More sharing options...
php_admin Posted June 7, 2009 Author Share Posted June 7, 2009 <?php switch(true) { case $temp < 10: $temperature_color = 'green'; $opacity = $temp*10; break; case $temp < 20: $temperature_color = 'yellow'; $opacity = $temp*5; break; case $temp < 30: $temperature_color = 'orange'; $opacity = $temp*3.3; break; default: $temperature_color = 'red'; $opacity = $temp*2.5; } ?> Thank you. Now, I just have to find a way to transfer the opacity value to CSS... unfortunately I can't just use the opacity command, because it isn't supported in all browsers. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 7, 2009 Share Posted June 7, 2009 http://www.drunkenfist.com/304/2007/07/09/cross-browser-opacity-using-css-and-internet-explorer-custom-filters/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.