How to give alternating table rows different background colors using PHP

前端 未结 6 502
面向向阳花
面向向阳花 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:28

    This is how I did it. I declared a css class called "even" with all the styling i wanted. Then looped through the scenario. Hope it helps!

    ";
        $i = 0;
        while($row = mysql_fetch_array($result))
        {
           if($i%2 == 0)
           {
              echo "
"; echo ""; echo ""; } else { echo ""; echo ""; echo ""; } $i++; } echo "
" . $row['something'] ." ". $row['something'] . "
" . $row['something'] ." ". $row['something'] . "
"; mysql_close($con); ?>

提交回复
热议问题