关于多级分类的求助,请高手指点一二
本人费尽心血做了一个递归的模型,但是结果显示的时候只输出顶级类,次级类没有输出出来:而此时表里有三条记录: channelid
channel
parentidkeywords
101001
现货行情 0 现货、行情 101001001 行情
101001
101002
供应信息 0
<?php
class Showtreemenu extends Model {
function Showtreemenu()
{
parent::Model();
}
function showbyselect($table,$field,$layer,$parentid){
$this->db->where($field,$parentid);
$query=$this->db->get($table);
if($query->num_rows()>0){
$select="<select name='channelid' id='channelid'>";
$result=$query->result_array();//print_r($result); return $select;exit;
foreach($result as $rec){
$channelid=trim($rec['channelid']);
$select.="<option value='$channelid'>";
for($i=1;$i<$layer;$i++){
$select.="|——";
}
$select.=$rec['channel'];
$select.="</option>";
$this->db->where($field,$rec['channelid']);
$query_sub=$this->db->get($table);
$result_sub=$query_sub->result_array();//$select=$query_sub->num_rows;return $select;exit;
$parentid=$channelid;
if($query_sub->num_rows>0){
$layer++;
$this->showbyselect($table,$field,$layer,$parentid);
$layer--;
}
}
$select.="</select>";
return $select;
}
}
}
?>
[ 本帖最后由 judy_zyzyx 于 2008-5-12 10:58 编辑 ]
页:
[1]