这个你可以这样来想,每一个分类都是相同的,只是内容不同而已。先定义一个模板,这个模板就是一种表格的格式,定义显示几行几列,每一个分类就是内容不同,因此只在那些需要改变的地方加上PHP代码就行。 $temp=ereg_replace('{CLASS}',$this->css_name,$this->html_table); $temp=ereg_replace('{ALIGN}',$align,$temp); $temp=ereg_replace('{BORDER}',$this->border,$temp); $temp=ereg_replace('{BD_COLOR}',$this->bd_color,$temp); $temp=ereg_replace('{BG_COLOR}',$this->bg_color,$temp); $temp=ereg_replace('{C_PADDING}',$this->cellpadding,$temp); $temp=ereg_replace('{C_SPAC}',$this->cellspacing,$temp); $temp=ereg_replace('{WIDTH}',$this->width,$temp); $temp=ereg_replace('{HEIGHT}',$this->height,$temp); $this->tbl_context.=$temp; } #Atomic Operation function add_row() { $this->tbl_context.=$this->html_tr; } #Atomic Operation #Param $in_array:每行各个列的内容 # $col_options:列设置(输入一个数组,按照如下顺序) # array('CSS源文件', # '对齐方式', # '列宽', # '列高', # '背景色') # 该数组如果不设置,则采用默认设置 function add_cols($in_array,$col_options=array()) { if(count($col_options)==0) $col_options=array('','center','','',''); $temp=ereg_replace('{CLASS}',$col_options[0],$this->html_td); $temp=ereg_replace('{ALIGN}',$col_options[1],$temp); $temp=ereg_replace('{WIDTH}',$col_options[2],$temp); $temp=ereg_replace('{HEIGHT}',$col_options[3],$temp); $temp=ereg_replace('{BG_COLOR}',$col_options[4],$temp); if(is_array($in_array)) { foreach($in_array as $val) { $this->tbl_context.=$temp.$val; } } else { $this->tbl_context.=$temp.$in_array;//输入非数组的情况 } } ###########用来创建表头############ ####参数$table_header可以是资源类型和数组类型 #### 若是资源类型则必须是mysql_query返回 #### 的资源类型.也可以调用mysql_DB类的db_query #### 方法. function create_table_header($table_header) { if (is_resource($table_header)) { $header_arr=array(); for ($i=0;$i<mysql_num_fields($table_header);$i++) array_push($header_arr,mysql_field_name($table_header,$i)); $this->add_row(); $this->add_cols($header_arr); } else if (is_array($table_header)) { $this->add_row(); $this->add_cols($table_header); } else echo ("传入了错误的参数!期望是数组或资源类型!<BR>"); }#创建数据表 function createDBTable($result) //$result为返回的结果资源 { while($row=mysql_fetch_array($result)) { $this->add_row(); foreach($row as $key=>$val) if(ereg('[0-9]',$key))//只要键为数字的值 $this->add_cols("$row[$key]"); } } function table_display() { echo "$this->tbl_context"; }}//end of class?>////////////////htmlTags.php的内容://///////////<?php$html_table="<table class=\"{CLASS}\" align=\"{ALIGN}\" border=\"{BORDER}\" bordercolor=\"{BD_COLOR}\" ";$html_table.="bgcolor=\"{BG_COLOR}\" cellpadding=\"{C_PADDING}\" cellspacing=\"{C_SPAC}\" ";$html_table.="width=\"{WIDTH}\" height=\"{HEIGHT}\" />";$html_tr="<tr />";$html_td="<td class=\"{CLASS}\" align=\"{ALIGN}\" width=\"{WIDTH}\" height=\"{HEIGHT}\" bgcolor=\"{BG_COLOR}\" />";?><?phpinclude "../DB/mysql_DB.inc";include 'genTable.inc';$db=new mysql_DB;$db->connectDB('localhost','root','','goods');$t=new ld_table('30','400','1','1','0','#000000','#0000ff','font.css');$t->initTable();$t->create_table_header($typeName.$typeQua)); //$typeName为产品类型名,$typeQua为该类产品数量。你可以用循环来每次改变这两个量,就构建出了不同的表头。(这里没有循环,所以只构建出一个表)这个方法是构造表头。$t->createDBTable($db->db_query($query)); //$query是发给数据库的请求,就是请求这种商品的名称和URL。这个方法是构建一个表的表体。$t->table_display();?>这个循环体你自己构造,应该不麻烦,思想就是上面说的。