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?');