亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

mysql - Interview question: How to print PHP three-level classification into a table for display?
漂亮男人
漂亮男人 2017-05-16 13:01:50
0
6
811

1. The structure of the classification table category is basically composed of three main fields: id, name, and parent_id
2. It needs to be printed and displayed in such a table format

3. How should I write php code? (Allows database table redesign)

漂亮男人
漂亮男人

reply all(6)
過去多啦不再A夢

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: 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 code
In 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;

}
這個是我的無限極分類,你的三級分類和我類似,只要渲染前段的時候注意就好了
phpcn_u1582

Using recursive queries in SQL

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template