PHP 无限级分类自用


//下拉框无限级分类
function getList($pid=0,&$result=array(),$spac=0){
    $spac = $spac+4;
    $sql = "select  * from deepcate where pid= $pid";
    $res = mysql_query($sql);
    while($row = mysql_fetch_assoc($res)){
        $row['catename'] =str_repeat(' ',$spac). '|--'.$row['catename'];
        $result[] = $row;
        getList($row['id'],$result,$spac);
    }
    return $result;

}

<?php

function displayCate($pid=0,$selected=1){
    $str='';
    $rs = getList($pid);
    $str.= "<select name='classify'>";
    foreach ($rs as $key=>$val) {
        $selectedstr = '';
        if($val['id'] == $selected){
            $selectedstr = "selected";
        }
        $str.= "<option value='{$val['id']}' {$selectedstr}>{$val['catename']}</option>";
    }
    return $str.= '</select>';
}
echo displayCate(0);

?>

//文件分类来源分类显示

function getCatePath($cid,&$result=array()){
    $sql = " select * from deepcate where id = $cid";
    $rs =mysql_query($sql);
    $row = mysql_fetch_assoc($rs);
    if($row){
        $result[]=$row;
        getCatePath($row['pid'],$result);
    }
    krsort($result);
    return $result;

}
<?php
function displayCatePath($cid,$url="cate.php?cid="){
    $res=getCatePath($cid);
    $str='';
    foreach ($res as $k=>$val){
        $str.="<a href='{$url}{$val['id']}'>{$val['catename']}</a>>";
    }
    return $str;
}

$sql_article = "select * from article where id ='{$data[0]['id']}'";
$classify = mysql_query($sql_article);
$classify_id = mysql_fetch_assoc($classify);

$sql = "select * from deepcate where id= '{$classify_id['article_classify']}'";
$value=mysql_query($sql);
$cid = mysql_fetch_assoc($value);

echo displayCatePath($cid["id"],'cate.php?page=1&id=');
?>

阅读更多
文章标签: PHP 分类 自用
个人分类: PHP
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭