yangzailu

导航

PHP无限分类分类导航LINK的代码实现

 1. 代码数据库的结构:

2.要达到的效果

 

/**
 * @param php无限分类分类导航LINK的代码实现
 */

include('db.inc.php');

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;
}
$res = getCatePath();

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

}

echo displayCatePath(10,'cate.php?');

 

posted on 2018-09-19 17:07  飞离地平线  阅读(346)  评论(0编辑  收藏  举报