建立一个高效的树表 Tree Table

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

查询子集
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}