递归目录树,怎样套上UL LI
本帖最后由 XingGuangYingYing 于 2013-04-15 08:18:54 编辑
‘.$row[‘name’].”;
nav($row[‘id’]);
echo ‘
‘.$row[‘name’].”;
$t = nav($row[‘id’]);
if(! empty($t)) $res .= “
function nav($parent){
$sql = mysql_query(“select * from menu where parent = ‘$parent'”);
while($row = mysql_fetch_array($sql)){
echo ‘
nav($row[‘id’]);
echo ‘
‘;
}
}
子类要怎么套上UL输出呢?
类似这样
- 音乐
- 流行
- 经典
- 80年代
- 90年代
- 电影
- 书籍
——解决方案——————–
你边查询边输出,于是你就无法知道当前节点是否有子节点(因为还未读到)
所以你需要想将查询结果读到数组 http://bbs.gaodaima.com/topics/390364669
然后再递归输出
你也可以用变量缓存待输出的内容,等递归结束时再输出
fun<span>!本文来源gaodai#ma#com搞*!代#%^码网5</span><pre>搞gaodaima代码
ction nav($parent){
$res = ”;
$sql = mysql_query(“select * from menu where parent = ‘$parent'”);
while($row = mysql_fetch_array($sql)){
$res .= ‘
$t = nav($row[‘id’]);
if(! empty($t)) $res .= “
- $t
“;
$res .= ‘
‘;
}
return $res;
}
调用时
echo nav($id);
我都是用 ajax 动态加载的,所以没有递归。
至少目前不适合你
搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:递归目录树,怎么套上UL LI
转载请注明原文链接:递归目录树,怎么套上UL LI
