Texan78 Posted January 4, 2015 Share Posted January 4, 2015 Hello, I have a small bit of code that changes the background color of a table cell depending on the value. It works great if I call the script by itself as you can see from this link. http://www.mesquiteweather.net/inc/inc-lake-levels.php But when I include it in on the page where I want to show it like so below, the background colors do not render color correctly as they as suppose to like from the link about, only the text color. <?php include("inc/inc-lake-levels.php"); ?> It looks like this. I call it in a the table like so. <td style="color:<?php echo $LRH_departTxt; ?>" bgcolor="<?php echo $LRH_departScale; ?>"> <?php echo $LRH_calcDepart; ?></td> I am not sure if this is a PHP problem or a CSS issue but here is the bit of code that creates the colors based on the values. First part is the background color, second part is the text. $LRH_departScale = ''; if ($LRH_calcDepart <= 0 && $LRH_calcDepart > -2) { $LRH_departScale = 'rgb(82, 71, 59)'; } else if ($LRH_calcDepart <= -2 && $LRH_calcDepart > -4) { $LRH_departScale = 'rgb(192, 185, 67)'; } else if ($LRH_calcDepart <= -4 && $LRH_calcDepart > -6) { $LRH_departScale = 'rgb(192, 102, 67)'; } else if ($LRH_calcDepart <= -6 && $LRH_calcDepart > - { $LRH_departScale = 'rgb(185, 64, 76)'; } else if ($LRH_calcDepart <= -8 && $LRH_calcDepart > -10) { $LRH_departScale = 'rgb(170, 59, 145)'; } else if ($LRH_calcDepart <= -10) { $LRH_departScale = 'rgb(115, 58, 167)'; } $LRH_departTxt = ''; if ($LRH_calcDepart <= 0 && $LRH_calcDepart > -2) { $LRH_departTxt = 'rgb(186, 245, 171)'; } else if ($LRH_calcDepart <= -2 && $LRH_calcDepart > -4) { $LRH_departTxt = 'rgb(255, 220, 177)'; } else if ($LRH_calcDepart <= -4 && $LRH_calcDepart > -6) { $LRH_departTxt = 'rgb(255, 219, 177)'; } else if ($LRH_calcDepart <= -6 && $LRH_calcDepart > - { $LRH_departTxt = 'rgb(254, 177, 185)'; } else if ($LRH_calcDepart <= -8 && $LRH_calcDepart > -10) { $LRH_departTxt = 'rgb(245, 170, 228)'; } else if ($LRH_calcDepart <= -10) { $LRH_departTxt = 'rgb(208, 169, 243)'; } Other than the background colors not rendering correctly when included all else works fine. Is there something I am not doing correctly that is causing this? I am not even sure where the first place to start looking would be. -Thanks Quote Link to comment https://forums.phpfreaks.com/topic/293641-else-if-values-not-rendering-correctly/ Share on other sites More sharing options...
Solution hansford Posted January 4, 2015 Solution Share Posted January 4, 2015 "bgcolor", haven't seen that one used in awhile. I would use CSS for this - I'm no expert on rgb, but the browser has the last say in how anything is rendered. Why do you need to use rgb btw - can't just use a class Quote Link to comment https://forums.phpfreaks.com/topic/293641-else-if-values-not-rendering-correctly/#findComment-1501661 Share on other sites More sharing options...
Texan78 Posted January 4, 2015 Author Share Posted January 4, 2015 "bgcolor", haven't seen that one used in awhile. Oh good God, I can't believe I overlooked that. This was a script a friend of mine started over a year ago and I was trying to finish it. Made the correct CSS changes to the below and all is good. style="color:<?php echo $LTaw_departTxt; ?>; background-color:<?php echo $LTaw_departScale; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/293641-else-if-values-not-rendering-correctly/#findComment-1501665 Share on other sites More sharing options...
QuickOldCar Posted January 4, 2015 Share Posted January 4, 2015 The semicolons were also missing in the original code for the style attributes. Quote Link to comment https://forums.phpfreaks.com/topic/293641-else-if-values-not-rendering-correctly/#findComment-1501670 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.