标签:
输出一个表格
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>23ptable</title>
</head>
<body>
<?php
echo ‘<table border="1" width="800" align="center">‘;
echo ‘<caption>使用一个while循环输出表格</caption>‘;
$i=0;
while($i<100){
if($i%10==0){
echo "<tr>";} #此处,$i%10=0,正好条件语句成立,输出<tr>
echo "<td>".$i."</td>";
$i++; #此处,$i仍然是0
if($i%10==0){
echo "</tr>";} /*此处,$i仍然是0,$i%10=0成立,但程序走出”}"后就是1了,若把$i++放在该if后面,<tr></tr>正好成对换行,后面的循环会自成一行*/
}
echo "</table>";
?>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
还可以实现隔行换色
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>23ptable</title>
</head>
<body>
<?php
echo ‘<table border="1" width="800" align="center">‘;
echo ‘<caption>使用一个while循环输出表格</caption>‘;
$i=0;
while($i<100){
if($i%10==0){
if($i%20==0){$bg="#fff999";}else{$bg="#333fff";} //效果如下图
echo "<tr bgcolor=$bg>";}
echo "<td>".$i."</td>";
$i++;
if($i%10==0){
echo "</tr>";}
}
echo "</table>";
?>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/exceed/p/4996431.html