树形结构与关系数据库之闭包表

闭包表记录了树中所有节点的关系,不仅仅只是直接父子关系,它需要使用2张表,除了节点表本身之外,还需要使用1张表来存储节祖先点和后代节点之间的关系(同时增加一行节点指向自身),
并且根据需要,可以增加一个字段,表示深度。因此这种方法数据量很多。设计的表结构如下:

create
table `node` ( `id` int(10) not null, `name` varchar(50) default null, primary key (`id`) ) engine=innodb default charset=utf8; create table `tree_path` ( `anc` int(10) not null comment '祖先节点', `des` int(10) not null comment '子孙节点', `pc` int(1) default null comment '是否为父子节点 1/0', primary key (`anc`,`des`) ) engine=innodb default charset=utf8; -- 示例树 -- root(0) -- | -- a(1) -- |___a1(2) -- |___a2(3) -- b(4) -- |___b1(5) -- |___b2(6) -- |___c(7) -- |___c1(8) -- |___d(9) -- |___e(10) insert into node(id,name) values (0,'root'); insert into node(id,name) values (1,'a'); insert into node(id,name) values (2,'a1'); insert into node(id,name) values (3,'a2'); insert into node(id,name) values (4,'b'); insert into node(id,name) values (5,'b1'); insert into node(id,name) values (6,'b2'); insert into node(id,name) values (7,'c'); insert into node(id,name) values (8,'c1'); insert into node(id,name) values (9,'d'); insert into node(id,name) values (10,'e'); insert into tree_path(anc,des,pc) values (0,1,1); insert into tree_path(anc,des,pc) values (0,2,0); insert into tree_path(anc,des,pc) values (0,3,0); insert into tree_path(anc,des,pc) values (0,4,1); insert into tree_path(anc,des,pc) values (0,5,0); insert into tree_path(anc,des,pc) values (0,6,0); insert into tree_path(anc,des,pc) values (0,7,0); insert into tree_path(anc,des,pc) values (0,8,0); insert into tree_path(anc,des,pc) values (0,9,0); insert into tree_path(anc,des,pc) values (0,10,0); insert into tree_path(anc,des,pc) values (1,1,0); insert into tree_path(anc,des,pc) values (2,2,0); insert into tree_path(anc,des,pc) values (3,3,0); insert into tree_path(anc,des,pc) values (4,4,0); insert into tree_path(anc,des,pc) values (5,5,0); insert into tree_path(anc,des,pc) values (6,6,0); insert into tree_path(anc,des,pc) values (7,7,0); insert into tree_path(anc,des,pc) values (8,8,0); insert into tree_path(anc,des,pc) values (9,9,0); insert into tree_path(anc,des,pc) values (10,10,0); insert into tree_path(anc,des,pc) values (1,2,1); insert into tree_path(anc,des,pc) values (1,3,1); insert into tree_path(anc,des,pc) values (4,5,1); insert into tree_path(anc,des,pc) values (4,6,1); insert into tree_path(anc,des,pc) values (4,7,1); insert into tree_path(anc,des,pc) values (4,8,0); insert into tree_path(anc,des,pc) values (4,9,0); insert into tree_path(anc,des,pc) values (4,10,0); insert into tree_path(anc,des,pc) values (7,8,1); insert into tree_path(anc,des,pc) values (7,9,1); insert into tree_path(anc,des,pc) values (7,10,0); insert into tree_path(anc,des,pc) values (9,10,1); 删除子树 假设要删除子树#7 delete from tree_path where tree_path.des in (select t.des from tree_path t where t.anc=7) 移动子树 假设我们要把子树#7从节点#4移动到节点#1 1.分离子树,删除子树节点与其祖先的关系 delete from tree_path where tree_path.anc=7 2.将上一步分离出的子树用笛卡尔积嫁接到#1下 select super.anc, sub.des, case when super.anc=1 and sub.des=7 then 1 else 0 end pc from tree_path super cross join tree_path sub where super.des=1 and sub.anc=7 查询树形结构 xxxxxx

 

打开dns.37it.cn免费申请二级域名解析方可使用 否则会出现00002993错误 用替换工具ultrareplace,文本编辑工具:Notepad++ 下面是需要替换的地方 ceshi.vvei.cn 超级人脉管家 http://mp.weixin.qq.com/s?__biz=MzA4MTI1OTI1OA==&mid=212268202&idx=1&sn=581c81665c013e1ee5c01db440df2593#rd 这个到时候自己撰写一份新手指南替换 掉 http://123.com/index.php?g=Admin&m=Login&a=index 后台地址 admin admin888 微信管理>>自定义回复 修改 http://ceshi.vvei.cn/ 替换为 你的网站 1、数据库连接地址:Public\Conf\config.php 2、微信菜单修改:Public\Conf\button_config.php,然后“微信管理”-“菜单管理”-“重新生成菜单”。 另下面三行代码请修改: $link_config (还没有关注的,引导关注,点击“立即关注”进入微信文章) $config_good_pic (购买时,页面上面的产品图) $headimgurl (没有购买前的头部左上角LOGO) 3、公众号里面的支付授权目录:直接域名就可以 支付回调URL:直接域名就可以 告警通知URL:先空着 4、更“换推广二维码”图片,图片在根目录保持格式、名字不变。记得在服务器根目录/imgpublic里删除其它多余的图片,只留benbendou.jpg即可。 5、页面的CSS在这里改:Application\Tpl\App\default\Public\Static\css 6、如果头像出不来,可以把根目录的imgpublic文件夹权限设为777 7、微信支付前显示的图片: Application\Tpl\App\default\Public\Static\images\productsinfo.jpg 对应更改的文件:Application\Tpl\App\default\Index\pay.html 8、更改下单时的“备注”内容:Application\Tpl\App\default\Index\index.html 9、关于修改微信关注后回复的内容目录地址: Application\Lib\Action\Admin\WechatAction.class.php 可修改第249,263,267行,可修改中文汉字,不要修改参数代码。 =============================================================== 后台登录:http://您的域名/index.php?g=Admin 初始帐号:admin 密 码:admin888
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值