動態生成一個m行n列的表格

yeahokay發表於2007-07-24
function MakeTable($rows,$columns,$width=80,$height=22){$table='';
for (
$i=0;$i<$rows;$i
++){$table.='';
for (
$j=0;$j<$columns;$j
++){$table.='
';
}
$table.='
';
}
$table.='
 
'
;
return
$table
;
}
//生成N行M列的表格echo MakeTable(n,m);[@more@]物件導向的
phpclass Bind{
public
$rows,$cells
;
public
$tabBgcolor,$trBgcolor
;
public
$table
function __construct($table
)
{
$this->table="$table";
//要繫結的表
$this->rows=""
;
$this->cells=""
;
$this->tabBgcolor="eeeeee"
;
$this->trBgcolor="white"
;
}
function
Cratetable
()
{
echo
"tabBgcolor style='font-size:12px'>";
$sql="select * from $this->table"
;
$res=mysql_query($sql) or die(mysql_error
());
$rs=mysql_fetch_array($res,1
);
echo
"
trBgcolor align=center style='font-family:Asia;font-size:16px'>";
foreach (
$rs as $key=>$value
)
{
echo
"
";
}
echo
"
";
for(
$i=0;$i<mysql_num_rows($res);$i
++)
{
echo
"
";
foreach (
$rs as $key=>$value
)
{
echo
"
";
}
echo
"
";
$rs=mysql_fetch_array($res,1
);
}
echo
"
$key
{$value}
"
;

}

}
$conn=mysql_connect("localhost","root",""
);mysql_select_db("test");$x=new Bind("test");$x->Cratetable();

?>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/786540/viewspace-927691/,如需轉載,請註明出處,否則將追究法律責任。

相關文章