首页 > 代码库 > PHP学习笔记之用php绘制表格示例

PHP学习笔记之用php绘制表格示例





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用php绘制表格示例</title>


<?php
  define(MAX_NUM, 20);
  $bc = "000000";
  $color = array();
  for ($i=0; $i<10000; $i++)
  {
$color[$i] = "#" . $bc;
$bc += 0x00000f;
//echo($color[$i] . "\t");
  }
  echo "<hr/>";
  
 
?>
</head>


<body>


<table border="2" cellspacing="0" cellpadding="0">
  <tr>
    <td width="40" height="40" <?php $r = rand(1, 9999); echo("bgcolor=\"$color[$r]\"") ?>>&nbsp;</td>
    <td width="40" height="40" <?php $r = rand(1, 9999); echo("bgcolor=\"$color[$r]\"") ?>>&nbsp;</td>
  </tr>
  <tr>
    <td width="40" height="40" bgcolor="#FFFF00">&nbsp;</td> 
    <td width="40" height="40" bgcolor="#FF00FF">&nbsp;</td>
  </tr>
</table> 


<table cellspacing="0" cellpadding="0">
  <?php
  for ($i=1; $i<=MAX_NUM; $i++)
  {
echo("<tr>");
for ($j=1; $j<=MAX_NUM; $j++)
{
$s = $i * $j;
$r = rand(1, 9999);
echo("<td  align=center width=\"40\" height=\"40\" "); 
echo(" bgcolor=\"$color[$r]\">   </td>");

}
echo("</tr>");
  }
  ?>
</table>


</body>
</html>

PHP学习笔记之用php绘制表格示例