<?php? include('db.inc.php'); function?deepcate($path=''){ $sql="SELECT?id,catename,path,concat(path,',',id)?as?fullpath?FROM?`deepcate`?WHERE?1?order?by?fullpath?asc"; $res=mysql_query($sql); $result=array(); while($row?=mysql_fetch_assoc($res)){ $deep=count(explode(',',trim($row['fullpath'],','))); $row['catename']=str_repeat(' ',$deep*4).'|--'.$row['catename']; ?$result[]=$row; } return?$result; } function?displayCateList(){ $res=deepcate(); $str="<select?name=cate>"; foreach($res?as?$key?=>$val){ ?$str.="<option>{$val['catename']}</option>"; } return?$str.="</select>"; } echo?displaycatelist(); function?getPathCate($cateid){ $sql="select?*,concat(path,',',id)?fullpath?from?deepcate?where?id=4"; $res=mysql_query($sql); $row=mysql_fetch_assoc($res); $ids=$row['fullpath']; $sql="select?*?from?deepcate?where?id?in?($ids)?order?by?id?asc"; $res=mysql_query($sql); $result=array(); while($row=mysql_fetch_assoc($res)){ $result[]?=?$row; } return?$result; } function?displayCatePath($cateid,$link='cate.php?cid='){ $res=getPathCate($catedid); $str=''; foreach($res?as?$k=>$v){ $str.="<a?href='{$link}{$v['id']}'>{$v['catename']}</a>>"; } return?$str; } echo?displaycatepath(4,'cate.php?p=1&cid='); ?>

Dream7115
2014-09-24
1 回答
舉報
0/150
提交
取消
2018-05-23
這位同學聽課很認真