展开全部
搞个无限级分32313133353236313431303231363533e4b893e5b19e31333361323632类,数据结构如下
id parent_id name
1 0 小明
2 1 小红
3 1 小刚
4 2 小紫
.....以此类推
$m = M('Table');
$data = $m->order('parent_id')->select();
$data = $this->tree($data, 0);
// 无限级分类
// 更过mysql查询http://it-school.cn/mysql/mysql-tutorial.html
static $treeList = array();
static public function tree(&$data, $parentId, $count = 1)
{
foreach ($data as $key => $value){
if($value['parent_id']==$parentId){
$value['Count'] = $count;
self::$treeList []=$value;
unset($data[$key]);
self::tree($data,$value['id'],$count+1);
}
}
return self::$treeList;
}