代码好像不能用图片贴出来晕
输出主目录
<?php
$result=$db->query("select id,title from newscata where fid=0");
while($rs=$db->fetch_array($result)){
$rs_v[$rs['id']]=$rs['title'];
}
foreach($rs_v as $key=>$val){
echo " <a href='?cataid=$key'>".$val."</a><br>";
tree($key);
}
unset($rs_v);
?>
输出子目录并递归调用
function tree($sid){
global $db;
$results=$db->query("select id,title,level from newscata where fid=$sid");
while($row=$db->fetch_array($results)){
$str=" ";
for($i=0; $i<=$row['level']-1; $i++){
$str=$str."→";
}
echo $str."<a href='?cataid=".$row['id']."'>".$row['title']."</a><br>";
}
unset($row);
unset($str);
}