求一个php的算法实现,实现如下:
将一个形如表1的树以表2的形式存储在一张数据库表中,现在希望删除一个子树(例如想删除Red子树)该怎么做呢?
Food
|--Fruit
|----Green
|------Pear
|----Red
|------Cherry
|------Apple
|----Yellow
|------Banana
|--Meat
|----Mutton
|----Beef
|----Pork
(表1)
ID parent title
1 Food
2 Food Fruit
3 Fruit Green
4 Green Pear
5 Fruit Red
6 Red Cherry
7 Fruit Yellow
8 Yellow Banana
9 Food Meat
10 Meat Mutton
11 Meat Beef
12 Meat Pork
13 Red Apple
(表2)
将一个形如表1的树以表2的形式存储在一张数据库表中,现在希望删除一个子树(例如想删除Red子树)该怎么做呢?
Food
|--Fruit
|----Green
|------Pear
|----Red
|------Cherry
|------Apple
|----Yellow
|------Banana
|--Meat
|----Mutton
|----Beef
|----Pork
(表1)
ID parent title
1 Food
2 Food Fruit
3 Fruit Green
4 Green Pear
5 Fruit Red
6 Red Cherry
7 Fruit Yellow
8 Yellow Banana
9 Food Meat
10 Meat Mutton
11 Meat Beef
12 Meat Pork
13 Red Apple
(表2)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货