How to give alternating table rows different background colors using PHP

前端 未结 6 497
面向向阳花
面向向阳花 2021-01-12 07:14

I have a table of data that is generated dynamically based on the contents stored in a mysql database.

This is how my code looks:

6条回答
  •  北海茫月
    2021-01-12 07:43

    Set a variable to true/false or a number and then back again during each iteration. Or use the modulus operator such as $i%2==0 in a while loop where $i is a number and use this condition in a ternary statement or something that sets the class value of the

Easiest way to alternate row colors in PHP/HTML?

$i = 0;
while ( $row = mysql_fetch_assoc($result) ) {
 echo '
'; $i++; }

提交回复
热议问题
' . $row['something'] . '