//获取表单 select 的无限极分类 $data 所有的数据 $pId 父级ID 第三个为默认值 第四个为 间隔
public function getTree_select($data, $pId ,$default,$space){
$html = '';
$space_nbsp='';
$nbsp=" ";
if($space){
for($i=0;$i<$space;$i++){
$space_nbsp.=$nbsp;
}
$space_nbsp.='└─';
}else{
$space_nbsp='';
}
$space++;
foreach($data as $k => $v)
{
if($v['adpid'] == $pId)
{
if($default==$v['adsortid']){
$selected='selected="selected"';
}else{
$selected='';
}
$html .= "<option $selected>".$space_nbsp.$v['subject']."</option>";
$html .= $this->getTree_select($data, $v['adsortid'],$default,$space);
}
}
return $html ;
}
public function is_sub($data, $pId){
$bean=0;
foreach($data as $k => $v)
{
if($v['adpid'] == $pId)
{
$bean=1;
}
}
return $bean;
}
//用上 获取 表格的 tr class_one为有展开图标的 class_two 是无展开图标的
public function getTree_tr($data, $pId ,$space){
$html = '';
$class_one='class="tdBG"';
$class_two='class="tdBG1"';
$class=$class_one;
$padding=15;
$space_nbsp='';
$nbsp=" ";
if($space){
$class=$class_two;
if($space>1){
$p_left=$padding*$space;
$p_left.='px';
$space_nbsp=" style='margin-left:$p_left'";
}else{
$space_nbsp=" style='margin-left:15px'";
}
}else{
$space_nbsp='';
}
$space++;
foreach($data as $k => $v)
{
if($v['adpid'] == $pId)
{
if($this->is_sub($data, $v['adsortid']) || $pId==0){
$class=$class_one;
}else{
$class=$class_two;
}
$html .= '<tr><td>'.$v['adsortid'].'</td>
<td align="left"><strong><span '.$class.' '.$space_nbsp.'>'.$v['subject'].'</span></strong></td>
<td><a href="/goods/ad/adcat_add.html?adsortid='.$v['adsortid'].'">修改</a> | <a href="/goods/ad/adcat_delete.html?adsortid='.$v['adsortid'].'" onclick="return confirm(\'确认删除么?\')">删除</a></td>
</tr>';
$html .= $this->getTree_tr($data, $v['adsortid'],$space);
}
}
return $html ;
}