php中常用的几种无限分类查询技术
2016-03-14 00:00
417 查看
数据库的设计
无限分类之一
全路径无限分类的优点在于 不需要递归
关键SQL语句是: $sql = 'select id,name,path,concat(path,"-",id) as fulpath from goods order by fulpath asc';
无限分类之一
//采用递归或者循环的思路 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(' ',$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(' ',$deep).'|--'.$row['catename']; $result[]=$row; } return $result; }
相关文章推荐
- php namespace use 用法
- 关于thinkphp部署到新浪云模板继承失效的问题
- thinkphp 没有直接创建数据库表的方法
- windows下tftp服务器
- WINCE开发中eboot模式下TFTP方式下载NK镜像时的问题
- 利用tftp和nfs下载文件到开发板
- WINCE开发中,EBOOT模式下,TFTP方式无法下载NK镜像的问题解决方案
- php中mysql数据库异步查询实现
- php和C# 面向对象继承
- mysql和php
- yii2-user 扩展插件的一些坑
- 安装php
- PHP——做服务
- 详解php中switch你可能不知道的事
- 详解php中switch你可能不知道的事
- 详解php中switch你可能不知道的事
- php策略模式
- 使用基于ThinkPHP3.2.3的ThinkAdmin创建手机电脑通用的表白墙(九)后台实现:整体概述
- PHP——smarty模板(做登录页面和主页面)
- PHP——smarty模板(第二天)