电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> PHP>>用php3创造动态的表格:

用php3创造动态的表格

来源:www.cncfan.com | 2006-1-11 | (有2215人读过)

class html_cell {
var $align, $valign, $width, $height, $bgcolor, $background, $rowspan, $colspan;
var $cell_content;

function show_cell() {
echo "<td ";
if ($this->align) {echo "ALIGN=".$this->align." ";}
if ($this->valign) {echo "VALIGN=".$this->valign." ";}
if ($this->width) {echo "WIDTH="".$this->width."" ";}
if ($this->height) {echo "HEIGHT="".$this->height."" ";}
if ($this->bgcolor) {echo "BGCOLOR="".$this->bgcolor."" ";}
if ($this->background) {echo "BACKGROUND="".$this->background."" ";}
if ($this->rowspan) {echo "ROWSPAN="".$this->rowspan."" ";}
if ($this->colspan) {echo "COLSPAN="".$this->colspan."" ";}
echo ">".$this->cell_content."</td>
";
}
}

class html_row {
var $align, $valign, $bgcolor, $background;
var $cell;

function new_cell($cell_content,$align,$valign,$width,$height,$bgcolor,$background,$rowspan,$colspan) {
$this->cell[] = new html_cell;
$newcell = new html_cell;
$newcell->cell_content = $cell_content;
$newcell->align = $align;
$newcell->valign = $valign;
$newcell->width = $width;
$newcell->height = $height;
$newcell->bgcolor = $bgcolor;
$newcell->background = $background;
$newcell->rowspan = $rowspan;
$newcell->colspan = $colspan;
$this->cell[sizeof($this->cell)-1] = $newcell;
}

function show_row() {
echo "<tr ";
if ($this->align) {echo "ALIGN=".$this->align." ";}
if ($this->valign) {echo "VALIGN=".$this->valign." ";}
if ($this->bgcolor) {echo "BGCOLOR="".$this->bgcolor."" ";}
if ($this->background) {echo "BACKGROUND="".$this->background."" ";}
echo ">";
for ($i=0;$i<sizeof($this->cell);$i++) {
$showcell = $this->cell[$i];
$showcell->show_cell();
}
echo "</tr>
";
}
}

class html_table {
var $border, $cellspacing, $cellpadding, $cols, $width, $height, $bgcolor, $background;
var $row;
var $center;

function new_row($align,$valign,$bgcolor,$background) {
$this->row[] = new html_row;
$newrow = new html_row;
$newrow->align = $align;
$newrow->valign = $valign;
$newrow->bgcolor = $bgcolor;
$newrow->background = $background;
$this->row[sizeof($this->row)-1] = $newrow;
}

function set_table_parameters($center,$border,$cellspacing,$cellpadding,$cols,$width,$height,$bgcolor,$background) {
$this->center = $center;
$this->border = $border;
$this->cellspacing = $cellspacing;
$this->cellpadding = $cellpadding;
$this->cols = $cols;
$this->width = $width;
$this->height = $height;
$this->bgcolor = $bgcolor;
$this->background = $background;
}

function new_cell($cell_content,$align,$valign,$width,$height,$bgcolor,$background,$rowspan,$colspan) {
$actualrow = new html_row;
$actualrow = $this->row[sizeof($this->row)-1];
$actualrow->new_cell($cell_content,$align,$valign,$width,$height,$bgcolor,$background,$rowspan,$colspan);
$this->row[sizeof($this->row)-1] = $actualrow;
}

function show_table() {
if ($this->center) {echo "<CENTER>
";}
echo "<table ";
if ($this->border) {echo "BORDER="".$this->border."" ";}
if ($this->cellspacing) {echo "CELLSPACING="".$this->cellspacing."" ";}
if ($this->cellpadding) {echo "CELLPADDING="".$this->cellpadding."" ";}
if ($this->cols) {echo "COLS="".$this->cols."" ";}
if ($this->width) {echo "WIDTH="".$this->width."" ";}
if ($this->height) {echo "HEIGHT="".$this->height."" ";}
if ($this->bgcolor) {echo "BGCOLOR="".$this->bgcolor."" ";}
if ($this->background) {echo "BACKGROUND="".$this->background."" ";}
echo ">
";
for ($i=0;$i<sizeof($this->row);$i++) {
$showrow = $this->row[$i];
$showrow->show_row();
}
echo "</table>
";
if ($this->center) {echo "</CENTER>
";}
}
}
#################################################################

$table = new html_table;
$table->set_table_parameters(1,0,3,3,0,760,0,"#0000FF",0);

$table->new_row("center","middle","#0000CC",0);
$table->new_cell("this is cell 1 on row 1",0,0,0,0,0,0,0,4);
$table->new_cell("this is cell 2 on row 1",0,0,149,0,0,0,0,0);

$table->new_row("center","middle","#000099",0);
$table->new_cell("this is cell 1 on row 2",0,0,0,0,"#000000",0,0,2);
$table->new_cell("this is cell 2 on row 2",0,0,0,0,0,0,2,0);
$table->new_cell("this is cell 3 on row 2",0,0,149,0,0,0,3,0);
$table->new_cell("this is cell 4 on row 2",0,0,149,0,0,0,0,0);

$table->new_row("center","middle","#000066",0);
$table->new_cell("this is cell 1 on row 3",0,0,0,0,0,0,0,0);
$table->new_cell("this is cell 2 on row 3",0,0,0,0,0,0,0,0);
$table->new_cell("this is cell 3 on row 3",0,0,149,0,0,0,0,0);

$table->new_row("center","middle","#000033",0);
$table->new_cell("this is cell 1 on row 4",0,0,149,0,0,0,0,0);
$table->new_cell("this is cell 2 on row 4",0,0,149,0,0,0,0,0);
$table->new_cell("this is cell 3 on row 4",0,0,149,0,0,0,0,0);
$table->new_cell("this is cell 4 on row 4",0,0,149,0,0,0,0,0);

$table->show_table();

#习惯的句法############
set_table_parameters(center,border,cellspacing,cellpadding,columns,width,height,bgcolor,background)

new_row(align,valign,bgcolor,background)

new_cell(cell_content,align,valign,width,height,bgcolor,background,rowspan,colspan)
PHP热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号