楼主你好,本人解答这个问题分为三个步骤:
1.数据库表设计
id int(6) not null auto_increment primary key
name varchar(20) not null ,
pid int(6),
sort int (6)
2.php代码如下:
class category{
Static Public function parents_to_child($data,$pid=0,$level=0,$html='--'){
$arr = array();
foreach($data as $v){
if($v['pid'] == $pid){
$v['level'] = $level+1;
$v['html'] = str_repeat($html,$level);
$arr[] = $v;
$arr = array_merge($arr,self::parents_to_child($data,$pid=$v['id'],$level=$level+1));
}
}
return $arr;
}
}
?>
3.在你需要分类的文件内载入类category,并引用静态方法
require 'category.class.php';
$cate = category::parents_to_child($data);
?>
以下代码是返回一个一维数组的无限分类
楼主可以根据本人所提供的代码根据自己的需求修改