Below is an example or a far simpler method of alternateing row colours. Good server side code should be unfussy, easy to understand and quick to execute.
// Define your colors for the alternating rows
$color1 = "#CCFFCC";
$color2 = "#BFD8BC";
$row_count = 0;
// Perform an statndard SQL query:
$sql_events = mysql_query("SELECT date_format(example_date, '%M %d, %Y') as example_date,
example_title FROM my_example ORDER BY example _date ASC") or die (mysql_error());
// Use the "$row" method for this query. This is just my preference.
while ($row = mysql_fetch_array($sql_examples)) {
$event_date = $row["example_date"];
$event_title = $row["example_title"];
/* Tell
php to alternate the colors between the two colors defined above. */
$row_color = ($row_count % 2) ? $color1 : $color2;
// Echo your table row and table data that you want to be looped over and over here.
echo "<tr>
<td width="110" bgcolor="$row_color" nowrap>
$example_date</td>
<td bgcolor="$row_color">
$example_title</td>
</tr>";
// Add 1 to the row count
$row_count++;
}
// Close out your table.
echo "</table>";