获取父节点的所有子节点
Get all the child nodes of parent nodes
我有一个从 Kartik Tree Manager 渲染的 treeview
。下面是我的树视图
Table
我想做什么?
我想select通过MySQL
查询Floor-1
的所有子节点
我试过运行如下查询
SELECT * FROM `mdc_node` m
WHERE m.`lft` = 11-2
输出
期望输出
我想要以下输出
------------------------------------------------------------
| `id` | `root` | `lft` | `rgt` | `lvl` | `name` | 'icon' |
------------------------------------------------------------
| 3 | 1 | 3 | 4 | 2 |GIS Office| folder |
| 4 | 1 | 5 | 6 | 2 | Ali | user |
| 5 | 1 | 7 | 8 | 2 | Usman | user |
| 6 | 1 | 9 | 10 | 2 | Faisal | user |
------------------------------------------------------------
下面是我的SQLFiddle
我要select父节点下的所有子节点
I want to select all the child nodes of Floor-1 via MySQL query
I want the following output
select * from mdc_node;
SELECT t1.id, t1.root, t1.lft, t1.rgt, t1.lvl, t1.name, t1.icon
-- from 1st copy of a table
FROM mdc_node t1
-- join 2nd copy of a table used for to get the info about needed parent
JOIN mdc_node t2
-- child nodes left and right are between left and right of their parent
ON t1.lft BETWEEN t2.lft AND t2.rgt
-- we need only the next level
AND t1.lvl = t2.lvl + 1
-- specify parent
WHERE t2.name = 'Floor-1';
唯一的问题 - 我不明白为什么 icon
行 id=3
在输出中是 'folder'
而在源数据中是 'user'
。
我有一个从 Kartik Tree Manager 渲染的 treeview
。下面是我的树视图
Table
我想做什么?
我想select通过MySQL
查询Floor-1
的所有子节点
我试过运行如下查询
SELECT * FROM `mdc_node` m
WHERE m.`lft` = 11-2
输出
期望输出
我想要以下输出
------------------------------------------------------------
| `id` | `root` | `lft` | `rgt` | `lvl` | `name` | 'icon' |
------------------------------------------------------------
| 3 | 1 | 3 | 4 | 2 |GIS Office| folder |
| 4 | 1 | 5 | 6 | 2 | Ali | user |
| 5 | 1 | 7 | 8 | 2 | Usman | user |
| 6 | 1 | 9 | 10 | 2 | Faisal | user |
------------------------------------------------------------
下面是我的SQLFiddle
我要select父节点下的所有子节点
I want to select all the child nodes of Floor-1 via MySQL query
I want the following output
select * from mdc_node;
SELECT t1.id, t1.root, t1.lft, t1.rgt, t1.lvl, t1.name, t1.icon
-- from 1st copy of a table
FROM mdc_node t1
-- join 2nd copy of a table used for to get the info about needed parent
JOIN mdc_node t2
-- child nodes left and right are between left and right of their parent
ON t1.lft BETWEEN t2.lft AND t2.rgt
-- we need only the next level
AND t1.lvl = t2.lvl + 1
-- specify parent
WHERE t2.name = 'Floor-1';
唯一的问题 - 我不明白为什么 icon
行 id=3
在输出中是 'folder'
而在源数据中是 'user'
。