Due to the need to extract the report data generated by multiple servers according to the conditions, we may use php to dynamically generate a table that supports cross-row and cross-column data. it is often difficult to control table cross-row and cross-column data, in addition, the logic coupling of the row and column merging attributes is very high, so there is a need for this time.
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"
". $ Col1_name ." |
". $ Col2_name ." |
". $ Col3_name ." |
";}Function baobiao_danteng ($ name, $ time_unit, $ pro_name, $ pre_name ){Echo"
$ Name |
". $ Pro_name [0]." | ";For ($ I = 0; $ I <$ time_unit; $ I ++ ){Echo"
". $ Pre_name. $ I .""; } Echo" |
";For ($ j = 0; $ j <(count ($ pro_name)-1); $ j ++ ){Echo"
". $ Pro_name [($ j + 1)]." | ";For ($ I = 0; $ I <$ time_unit; $ I ++ ){Echo"
". $ Pre_name. $ I .""; } Echo ""; } } Function finish (){ Echo ""; } } ?> The call method is as follows: The code is as follows: $ Init = new danteng (); $ Init-> init ('type', 'project', 'unit of Time ', $ time_num ); $ Init->; baobiao_danteng ('fuxi ', $ time_num, $ fuxi_pro, 'pre _ n '); $ Init->; baobiao_danteng ('nvwa ', $ time_num, $ nvwa_pro, 'unit '); $ Init->; baobiao_danteng ('pangu ', $ time_num, $ pangu_pro, 'AH '); $ Init->; baobiao_danteng ('xiaoye', $ time_num, $ pangu_pro, 'egi '); $ Init->; finish (); |