I’m trying to make in sort that odd <tr> and even <tr> have different color for easier reading.
Here’s my code:
$show_res = mysql_query($show_query);
while ($show_row = mysql_fetch_assoc($show_res)){
$rc++;
if (($rc > 1)){
$tr = '#cccccc';
} else {
$tr = '#ffffff';
}?>
<tr style="background-color:<?php echo $tr ;?>">
It doesn’t work, am I missing something?
You want to use modulo %
Some examples:
So based on whether the remainder is 1 or 0 you change the color. And you want the
<tr>element to be a part of your loop as that’s constantly being changed from one color or the other, back and forth.