Home > Article > Backend Development > How to realize two colors of table in php
php method to realize two colors of table: 1. Create a table; 2. Use PHP code "$i =0;while($i
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How does php realize the two colors of the table?
[PHP] Implementation of simple interlaced color-differentiated tables
<html> <head> <title>Creating tables</title> <meta charset="utf-8" /> </head> <body> <table border="1" style = 'border-collapse: collapse;'align="center"> <caption><h1>表格示意图</h1></caption> <tr> <th>学号</th> <th>年级</th> <th>姓名</th> <th>性别</th> <th>政治面貌</th> <th>年龄</th> <th>成绩</th> <th>等级</th> <th>奖学金</th> <th>有无违纪</th> </tr> <?php $i =0; while($i<20){//第一层循环,将第一行循环20 if($i%2==0){//对数据行进行判断,当为偶数行时,灰色赋给$bgcolor $bgcolor = 'BBBBBB'; }else{ $bgcolor = 'FFFFFF'; } $i++; echo "<tr>"; $j=0; while ($j<10){//第二层循环,得到10个数据 $j++; echo "<td style = 'text-align :center' bgcolor = $bgcolor>数据</td>"; } echo "</tr>"; } ?> </table> </body> </html>
Rendering:
Recommended study:《PHP video tutorial》
The above is the detailed content of How to realize two colors of table in php. For more information, please follow other related articles on the PHP Chinese website!