Alternating Row Colors in a Table in HTML
Posted: Mon Jun 27, 2005 2:05 pm
Hello~
I would like to alternate row colors in a table that is generated from a mySQL result set. The table is generated from a while loop. Basically i would like the 2nd row to have a class type of 'highlightedrow' how do i write the code to do that? here is what i have so far:
Thanks in advance
Dan

I would like to alternate row colors in a table that is generated from a mySQL result set. The table is generated from a while loop. Basically i would like the 2nd row to have a class type of 'highlightedrow' how do i write the code to do that? here is what i have so far:
Code: Select all
<?php
$query = 'select *
from class_groups
where =' .$_POST['scheduletype'].;
$r = mysql_query($query);
$row = mysql_fetch_array ($r)
?>
<table width="100%" border="0" cellspacing="0">
<tr>
<td colspan="5" class="subTitle"><?php {print "{$row['Group_Name']}";} ?></td>
</tr>
<tr>
<td class="headerRow"><div align="center">Class Name </div></td>
<td class="headerRow"><div align="center">Day of Week </div></td>
<td class="headerRow"><div align="center">Time</div></td>
<td class="headerRow"><div align="center">Age Group </div></td>
<td class="headerRow"><div align="center">Register Online </div></td>
</tr>
<? while ($row = mysql_fetch_array ($r))
{
?>
<tr <!--here is where i want to alternate colors by choosing a CSS Class type-->>
<td><?php {print "{$row['Class_name']}";} ?></td>
<td><?php {print "{$row['Day_of_week']}";} ?></td>
<td><?php {print "{$row['Time']}";} ?></td>
<td><?php {print "{$row['Age_group']}";} ?></td>
</tr>
<?php } ?>Thanks in advance
Dan