菜单

category无限递归分类

2010年04月8日 - typo3
function buildTree($pid=0,$content='',$key=0) {
    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery("*","table_category","parent_id=".$pid);
    while(false != ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))){
        $space = '';
        for($i=0;$i<$key;$i++){$space.="  ";}   //生成空格
        $content .= "";
        $content = $this->buildTree($row['id'],$content,$key+1);
    }
    return $content;
}

 

升级版:(edit)

/**
* buildCategory
* @param $id
* @param $params
* @param $useCache
*/
function buildCategory($id=0,$content=”,$key=0,$local_id = 0) {
$cat_id = -1;
if ($local_id>0) {
$cat_id_array = $this->find_mm_result($local_id,’tx_blog_post_cat_mm’);
}
$res = $GLOBALS[‘TYPO3_DB’]->exec_SELECTquery(“*”,”tx_blog_cat”,”hidden=0 and deleted=0 and pid=”.$GLOBALS[‘Pid’].” and parent_id=”.$id);
while(false != ($row = $GLOBALS[‘TYPO3_DB’]->sql_fetch_assoc($res)))
{
$selected = ”;
if ($row[‘uid’] == $cat_id_array[0]){
$selected = ‘selected=”selected”‘;
}
$space = ”;
for($i=0;$i<$key;$i++){$space.=”&nbsp;&nbsp;”;}
$content .= “<option value='”.$row[‘uid’].”‘ “.$selected.”>”.$space.$row[‘catname’].”</option>”;
$content = $this->buildCategory($row[‘uid’],$content,$key+1,$local_id);
}
return $content;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注