I am creating a table (stats_1) dynamically and would like to have each row of a different background color. So far, all lines have the same background color.
I have the following PHP code that prints echoes and instructions:
$keys = array('Col1', 'Col2','Col3','Col4','Col5','Col6','Col7'); echo '<table id="stats_1"><tr>'; foreach ($keys as $column) echo '<th>' . $column . '</th>'; echo '</tr>'; foreach ($data as $row){ echo '<tr class="alt">'; foreach ($keys as $column) if (isset($row[$column])){ echo '<td>' . $row[$column]; } else { echo '<td>' . '' . '</td>'; } } echo '</table>';
I need help when EVERY OTHER Row ($ row) has a different COLOR, but I donβt know how to do this programmatically using the echo instruction. Thus, it will alternate printing between:
echo '<tr class="alt">'; or echo '<tr>';
I define that in a class:
#stats_1 tr.alt td { color:#000000; background-color:#E0E0FF; }
Thanks for the help / contribution.
source share