Here's what I was doing (as part of a PHP echo):
<td bgcolor={$row['AwayB']}><font color={$row['AwayF']}>{$row['AwayTeam']}</font></td>
Then I found some CSS to alternate table row background colours:
table.sortable tbody tr:nth-child(2n) td {
background: #666;
}
table.sortable tbody tr:nth-child(2n+1) td {
background:#333;
}
But then the background colour was the same the whole way across the row, instead of changing for the two table cells it should change for (the second is almost identical to the first, just with 'home' instead of 'away'). And apparently I should be using CSS instead of the font tag anyway.
So I knocked together this in the stylesheet to test:
table.sortable tbody tr td.awayTeam {
background-color:#900;
}
And removed the bgcolor code from the td tag and replaced it with class='awayTeam'. And it worked. And I found something on CSS-Tricks about using variables with CSS, and tried that, with this at the top of the CSS:
<?php
header("Content-type: text/css; charset: UTF-8");
$bgcolor = "#900";
?>
And then this as the style:
table.sortable tbody tr td.awayTeam {
background-color:<?php echo $bgcolor; ?>;
}
Still worked. So I replaced $bgcolor with $row['AwayB'], and "{$row['AwayB']}", and ($row['AwayB'])...and all three just returned
table.sortable tbody tr td.awayTeam {
background-color:;
}
Is there a way I can make this work?
EDITED TO ADD: Moving the CSS code into the while loop used to generate the table overrides the zebra striping and uses the team colour of the last team in the table for all teams. Overriding the zebra striping isn't a huge deal--the team colours provide enough differentiation--but obviously the colours need to work.
I need to keep the zebra striping in the table class, because I need that class for sorting and there are other, non-sports tables that need the background differentiation.