Are there any potential pitfalls to be aware of when implementing alternating row colors in PHP?

One potential pitfall to be aware of when implementing alternating row colors in PHP is ensuring that the logic for determining the row color is correctly implemented. This includes properly incrementing a counter variable and using it to determine whether to apply a specific color to a row. Failing to do so may result in incorrect row colors being applied or rows being skipped.

<?php
// Example code for implementing alternating row colors in PHP
$counter = 0;
while ($row = $result->fetch_assoc()) {
    if ($counter % 2 == 0) {
        $row_color = 'even';
    } else {
        $row_color = 'odd';
    }
    
    // Output row with alternating color
    echo '<tr class="' . $row_color . '">';
    // Output row data here
    echo '</tr>';
    
    $counter++;
}
?>