本文实例讲述了PHP实现无限极分类生成分类树的方法。分享给大家供大家参考,具体如下:
现在的分类数据库设计基本都是:每一个分类有一个id主键字段,一个pid指向父类的id,这样便可实现无限级分类,取出的数据就是如下的格式:
$arr = array(
array("id" => 1 , "pid" => 0 , 'cat' => '栏目一'),
array("id" => 2 , "pid" => 0 , 'cat' => '栏目二'),
array("id" => 3 , "pid" => 1 , 'cat' => '栏目三'),
array("id" => 4 , "pid" => 2 , 'cat' => '栏目四'),
array("id" => 5 , "pid" => 1 , 'cat' => '栏目五'),
array("id" => 6 , "pid" => 5 , 'cat' => '栏目六'),
array("id" => 7 , "pid" => 5 , 'cat' => '栏目七'),
array("id" => 8 , "pid" => 6 , 'cat' => '栏目八'),
array("id" => 9 , "pid" => 1 , 'cat' => '栏目九'),
array("id" => 10 , "pid" => 0 , 'cat' => '栏目十'),
array("id" => 11 , "pid" => 10 , 'cat' => '栏目十一'),
array("id" => 12 , "pid" => 11 , 'cat' => '栏目十二'),
array("id" => 13 , "pid" => 2 , 'cat' => '栏目十三'),
array("id" => 14, "pid" => 13 , 'cat' => '栏目十四')
);
页:
[1]