84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
1.分类表category的结构基本是id,name,parent_id三个主要字段组成2.需要打印显示成这样的表格格式
3.应该怎么编写php代码?(允许重新设计数据库表)
Already set level 3, what is level 3!? Just connect it yourself twice.
select c1.name "一级分类", c2.name "二级分类", c3.name "三级分类" from category c1 inner join category c2 on c1.id=c2.parent_id inner join category c3 on c2.id=c3.parent_id where c1.parent_id=0 #最高级;
This way you can get the watch you want.
php unlimited classification database design
The database is divided into three tables: first_level, second_level, third_level
first_level, second_level, third_level
first_level: id, name; second_level: id, parent_id, name // second_level.parent_id = first_level.id third_level: id, parent_id, name // third_level.parent_id = second_level.id
First traverse the level 3 array and throw it into the level 2 sub-item array, similar to Infinitus going in reverse
What you masters want is php codeIn fact, it is a reordering problem. The second and third level classifications included under the first level classification,
static public function toLevel($cate, $delimiter = '|——', $parent_id = 0, $level = 0) { $arr = array(); foreach ($cate as $v) { if ($v['parent_id'] == $parent_id) { $v['type'] = $level + 1; $v['delimiter'] = str_repeat($delimiter, $level); $arr[] = $v; $arr = array_merge($arr, self::toLevel($cate, $delimiter, $v['cate_id'], $v['type'])); } } return $arr; } 这个是我的无限极分类,你的三级分类和我类似,只要渲染前段的时候注意就好了
Using recursive queries in SQL
Already set level 3, what is level 3!? Just connect it yourself twice.
This way you can get the watch you want.
php unlimited classification database design
The database is divided into three tables:
first_level, second_level, third_level
First traverse the level 3 array and throw it into the level 2 sub-item array, similar to Infinitus going in reverse
What you masters want is php code
In fact, it is a reordering problem. The second and third level classifications included under the first level classification,
Using recursive queries in SQL