1.创建数据表
CREATE TABLE category(
`cat_id` SMALLINT unsigned not null auto_increment comment '类别id',
`cat_name` VARCHAR(30) not null default '' comment '类别名称',
`par_id` SMALLINT unsigned not null default 0 comment '类别父id',
PRIMARY KEY (`cat_id`)
)engine=myisam default charset=utf8;
2. 编写一个函数,递归遍历,实现无限分类
function tree($arr,$pid=0,$level=0)
{static $list = array();foreach ($arr as $v){//如果是父节点,则将其存到$list中//并以此节点作为根节点,遍历其子节点if($v['par_id'] == $pid){$v['level'] = $level;$list[] = $v;tree($arr,$v['cat_id',$level+1);}}return $list;
}