返回顶部

收藏

建立一个高效的树表 Tree Table

更多
查询子集
SELECT * FROM `table` WHERE `pid` = 3

查询子孙集
SELECT * FROM `table` WHERE `place` LIKE '%/3/%'

查询某代子集
SELECT * FROM `table` WHERE `place` LIKE '%/3/%' AND `level` = 4

插入
$insert_id = INSERT INTO `table` (`name`,`pid`) VALUES('面试专员','10')
$parent = SELECT * FROM `table` WHERE `id` = 10 
UPDATE `table` SET `place` = '{$parent['place']}{$insert_id}/',`level`= {$parent['level']} + 1 WHERE `id` = {$insert_id}

修改父级
$parent = SELECT * FROM `table` WHERE `id` = {$pid}
UPDATE `table` SET `pid` = {$pid},`place` = '{$parent['place']}{$insert_id}/',`level`= {$parent['level']} + 1 WHERE `id` = {$id}

标签:sql

收藏

0人收藏

支持

0

反对

0