Jump to content

Else If values not rendering correctly


Go to solution Solved by hansford,

Recommended Posts

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. 

 

RUixY2.png

 

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

Link to comment
https://forums.phpfreaks.com/topic/293641-else-if-values-not-rendering-correctly/
Share on other sites

"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; ?>">
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.