Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
yii或mysql或php获取所有子类别树_Php_Mysql_Yii_Tree - Fatal编程技术网

yii或mysql或php获取所有子类别树

yii或mysql或php获取所有子类别树,php,mysql,yii,tree,Php,Mysql,Yii,Tree,mysql中的表: id | name | prent ---------------------------- 1 | cat1 | 0 2 | cat1.1 | 1 3 | cat2.1 | 1 4 | cat11.2 | 2 5 | cat11.4 | 4 6 | cat1 | 0 我希望当选择id 1(cat1)时,我希望获得所有子类别id。结果:“2,3,4,5”如果需要,请选择所有子类别添加列

mysql中的表:

id | name        | prent
----------------------------
1  | cat1        | 0
2  | cat1.1      | 1
3  | cat2.1      | 1
4  | cat11.2     | 2
5  | cat11.4     | 4
6  | cat1        | 0

我希望当选择id 1(cat1)时,我希望获得所有子类别id。结果:“2,3,4,5”

如果需要,请选择所有子类别添加列路径

id | name        | parent | path
-----------------------------------
1  | cat1        | 0      | 0-1
2  | cat1.1      | 1      | 0-1-2
3  | cat2.1      | 1      | 0-1-3
4  | cat11.2     | 2      | 0-1-2-4
5  | cat11.4     | 4      | 0-1-2-4-5
6  | cat1        | 0      | 0-6
和查询:

SELECT * FROM tree WHERE path LIKE '0-1-%' ORDER BY path ASC;

path_parent = concat('0','-',id_parent)

path_child = concat('path_parent', '-', 'id_child')

您可以通过查询来完成。你需要为它写一个过程。我想要孩子id,而不是父母