php中常用的几种无限分类查询技术

编程入门 行业动态 更新时间:2024-10-17 15:27:06

php中常用的<a href=https://www.elefans.com/category/jswz/34/1769370.html style=几种无限分类查询技术"/>

php中常用的几种无限分类查询技术

数据库的设计 无限分类之一

//采用递归或者循环的思路
function getList($pid=0,&$result=array(),$spac=0)
{$spac = $spac+2;$sql = "select * from deepcate where pid = $pid";$res = mysql_query($sql);while($row=mysql_fetch_assoc($res)){$row['catename'] = str_repeat('&nbsp;',$spac) . '|--' . $row['catename'];$result[] = $row;getList($row['id'],$result,$spac);}return $result;
}
$rs = getList();
print_r($rs);
}

全路径无限分类

全路径无限分类的优点在于 不需要递归 关键SQL语句是: $sql = 'select id,name,path,concat(path,"-",id) as fulpath from goods order by fulpath asc';

function likedate($path="")
{$sql ="select id,name,path,concat(path,"-",id) as fulpath from goods order by fulpath asc";$res=mysql_query($sql);$result = array();while($row = mysql_fetch_assoc($res)){$deep = count(explode(',',trim($row['fullpath'],',')));$row['catename] = str_repeat('&nbsp;&nbsp;',$deep).'|--'.$row['catename'];$result[]=$row;}return $result; 
}

转载于:

更多推荐

php中常用的几种无限分类查询技术

本文发布于:2024-02-26 18:10:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1703413.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几种   常用   技术   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!