Home  >  Article  >  Backend Development  >  PHP dynamically implements table cross-row and cross-column implementation code

PHP dynamically implements table cross-row and cross-column implementation code

高洛峰
高洛峰Original
2016-12-01 11:16:251188browse

Copy code The code is as follows:

< ?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 ""; 
} 
} 
?>

The calling method is as follows:
Copy code The code is as follows:
$init = new danteng();
$init -> init('type', 'project', 'time unit', $time_num);
$init ->; baobiao_danteng('Fuxi', $time_num, $fuxi_pro, 'pre_n');
$init ->; baobiao_danteng('Nuwa', $time_num, $nvwa_pro, 'unit ');
$init ->; baobiao_danteng('Pangu', $time_num, $pangu_pro, 'ah');
$init ->; baobiao_danteng('Xiaoye', $time_num, $pangu_pro, 'danzi' );
$init ->; finish();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP extension to mongodbNext article:PHP extension to mongodb