Home  >  Article  >  Backend Development  >  How to realize two colors of table in php

How to realize two colors of table in php

藏色散人
藏色散人Original
2022-01-21 09:58:303407browse

php method to realize two colors of table: 1. Create a table; 2. Use PHP code "$i =0;while($i

How to realize two colors of table in php

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 = &#39;border-collapse: collapse;&#39;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 = &#39;BBBBBB&#39;;
}else{
$bgcolor = &#39;FFFFFF&#39;;
}
$i++;        
echo "<tr>";
$j=0;
while ($j<10){//第二层循环,得到10个数据
$j++;
echo "<td style = &#39;text-align :center&#39; bgcolor = $bgcolor>数据</td>";
}
echo "</tr>";
}
?>
</table>
</body>
</html>

Rendering:

How to realize two colors of table in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn