Home >Database >Mysql Tutorial >建立一个高效的树表 Tree Table

建立一个高效的树表 Tree Table

WBOY
WBOYOriginal
2016-06-07 14:56:221070browse

打开此地址查看, 永久有效 ,老手绕行 领接表增强 + MPTT 两种模式 http://mat1.gtimg.com/hb/js/common/demo/tree.html 超快查询所有子孙 画个table,写了样式,居然被替换的面目全非,所以,干脆做成HTML算了。 无 查询子集SELECT * FROM `table` WHERE `p

打开此地址查看, 永久有效 ,老手绕行
领接表增强 + MPTT 两种模式
http://mat1.gtimg.com/hb/js/common/demo/tree.html


超快查询所有子孙

画个table,写了样式,居然被替换的面目全非,所以,干脆做成HTML算了。


查询子集
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}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn