Entry
How to change each table row color, based on the date (10.05.2001=black, 10.04.2001=#white etc.....)
Oct 25th, 2001 03:59
Alder Rus, Ilya Poropudas, sh, Dennis Kaandorp, Onno Benschop,
hi !
create id's for those tr's where you want to change the color.
then you can go and use some javascript:changeIt(tr1)
like
function changeIt(pIndex) {
with(document.theForm) {
if(pIndex == "tr1") {pIndex.style.bgcolor="black";}
}
}
and so on
;)
-sh
-----
While I like the answer above, it may not be the best solution to what the
question means. If you want to just vary the cell background colors per day,
you could use one variable to check whether the instance is the first for that
date and another variable to cycle the color(s).
In MySQL this could be done (with white and gray) like this:
while ($row = mysql_fetch_array($query_result)) {
print("<tr ");
$currentDate = $row["date"];
if ($currentDate != $lastDate)
{
if ($cellBgColor=="#FFFFFF")
{
$cellBgColor = "#CCCCCC";
}
else
{
$cellBgColor = "#FFFFFF";
}
print("bgcolor=$cellBgColor");
}
print(">");
$lastDate = $currentDate;
}