• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

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)
3 Solutions
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...

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now