微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php怎么实现表格两种颜色

PHP实现表格两种颜色的方法:1、创建一个table表格;2、通过PHP代码“$i =0;while($i<20){if($i%2==0){$bgcolor = 'BBBBBB';}else{$bgcolor...;}”实现隔行变颜色即可。

本文操作环境:Windows7系统、PHP7.1版、DELL G3电脑

PHP怎么实现表格两种颜色?

PHP】简单的隔行颜色区分表格的实现

<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>

效果图:

b110ec797b154fe2581c836e705f0f2.png

推荐学习:《PHP教程

原文地址:https://www.jb51.cc/php/2916261.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐