php动态实现表格跨行跨列实现代码
投稿:mdxy-dxy
由于按照条件提取多台服务器生成的报表数据的需要,我们很可能用到php动态生成可以跨行跨列的表格,table跨行跨列杂糅在一起经常出现不好控制,而且行列合并属性的逻辑耦合度很高,所以对于这次的需要就有了如下东西
复制代码 代码如下:
< ?php
/*
* author:xudafeng@126.com
* blog:http://www.xdf.me
* date:2012.7.28
*/
class danteng {
function init($col1_name, $col2_name, $col3_name, $time_unit) {
echo "<table border=1><tr><th>" . $col1_name . "</th><th>" . $col2_name . "</th><th colspan=\"" . $time_unit . "\">" . $col3_name . "</th></tr>";
}
function baobiao_danteng($name, $time_unit, $pro_name, $pre_name) {
echo "<tr><th rowspan=\"" . count($pro_name) . "\">$name</th><td>" . $pro_name[0] . "</td>";
for ($i = 0; $i < $time_unit; $i++) {
echo "<td>" . $pre_name . $i . "";
}
echo "</tr>";
for ($j = 0; $j < (count($pro_name) - 1); $j++) {
echo "<tr><td>" . $pro_name[($j + 1)] . "</td>";
for ($i = 0; $i < $time_unit; $i++) {
echo "<td>" . $pre_name . $i . "";
}
echo "";
}
}
function finish() {
echo "";
}
}
?>