目的:了解全局变量和静态变量的使用
步骤1:写一个表单(table1.html)
步骤二:点击提交后到对应的方法中处理
<?php
namespace Home\Controller;
use Think\Controller;
//用户相关信息及设置
class DemoController extends Controller {
public function table1(){
if(IS_POST){
global $num;global $rows;
$num = 0;$rows=0;
echo "<table border='1' style='border-collapse:collapse;margin:0 auto;text-align:center;'>";
$this->test(I('post.max_num'),I('post.cols_num'),I('post.incre'));
if($num%I('post.cols_num')!=0){
for ($i=0; $i <I('post.cols_num')-$num%I('post.cols_num'); $i++) {
echo "<td >空</td>";
}
}
echo "<tr/></table>";
}else{
$this->display();
}
}
/*
**$num 有实际数据的表格单元格数
**$rows 表格有多少行
**$max 最大值
**$cols 表格的列数
**$plus 表格值的递增数
*/
public function test($max,$cols,$plus){
static $a = 1, $b=1;
global $num ,$rows;
if($a<$max){
if($b==1){
echo "<tr>";
}
echo "<td style=\"min-width:80px;\">".$a."</td>";
$a+=$plus;
$b++;$num++;
if($b>$cols){
echo "</tr>";
$b = 1;
$rows++;
}
$this->test($max,$cols,$plus);
}
}
}
效果如下图: