<?php
function getCatePath($cid,&$result=array()){
include("conn.php");
$sql="select * from list where id=$cid";
$rs=mysqli_query($link,$sql);
$row=mysqli_fetch_array($rs);
if($row){
$result[]=$row;
getCatePath($row['pid'],$result);
}
krsort($result);
return $result;
}
function displayCatePath($cid){
$res=getCatePath($cid);
$str='';
foreach ($res as $key => $val) {
$str.="<a href='cate.php?cid={$val['id']}'>{$val['catename']}</a>>";
}
return $str;
}
echo displayCatePath(10);
实现效果: