dynamic rgb value not working

I have the following code:

echo '<td bgcolor="rgb(255, '.(255-$count_ac).','.(255-$count_ac).')">&nbsp;</td>';

----- $count_ac is a simple variable that house a number -----

after processing, it presents properly like the following:

<td bgcolor="rgb(255, 248,248)">

But the color displayed is a dark green -- it should be light red (pink)
Who is Participating?
Marco GasiFreelancerCommented:
As W3C says "The bgcolor attribute of <td> is not supported in HTML 4.01 Strict / XHTML 1.0 Strict DTD." so check your DOCTYPE definition.

Ray PaseurCommented:
You may still be able to get away with using something like this (obviously untested code)...  But the correct way to handle this is to use style sheets.

$r  = dechex(255);
$g  = dechex(255 - $count_ac);
$b  = dechex(255 - $count_ac);
$bg = '#' . $r . $g . $b;
$st = 'span style="background-color:' $bg . '"';
$td = "<td $st>&nbsp;</td>";
echo $td;

Open in new window

Why in the world would you use an obsolete property like bgcolor instead of styling it with:
echo '<td style="background-color:rgb(255,' . 255-$count_ac.','.255-$count_ac.')">&nbsp;</td>';

Then at least it would work consistently in virtually all browsers that have been manufactured in the last 10 years. Even as far back as IE4.  and everything in the future.

edavoAuthor Commented:
Thats what I resorted too - I used a class for each counter - Thank You...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.