I am currently developing a category hierarchy, and I got the point of creating tree treversal i think. But I need to add a new node into this hierarchy usign PHP function.
The problem is rebuild_tree function would be good enough (in other words, efficient with large trees).
Sample query:
CREATE TABLE `t_categories`(
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(45) NOT NULL,
`lft` INTEGER UNSIGNED NOT NULL,
`rght` INTEGER UNSIGNED NOT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO t_categories (title, lft, rght) VALUES ('Cat 1',1,16);
INSERT INTO t_categories (title, lft, rght) VALUES ('Cat 2',2,3);
INSERT INTO t_categories (title, lft, rght) VALUES ('Cat 3',4,7);
INSERT INTO t_categories (title, lft, rght) VALUES ('Cat 4',5,6);
INSERT INTO t_categories (title, lft, rght) VALUES ('Cat 5',8,13);
INSERT INTO t_categories (title, lft, rght) VALUES ('Cat 6',9,12);
INSERT INTO t_categories (title, lft, rght) VALUES ('Cat 7',10,11);
INSERT INTO t_categories (title, lft, rght) VALUES ('Cat 8',14,15);
Table results look like that:
ID TITLE LFT RGHT
1 Cat1 1 16
2 Cat2 2 3
3 Cat3 4 7
4 Cat4 5 6
5 Cat5 8 13
6 Cat6 9 12
7 Cat7 10 11
8 Cat8 14 15
I gave sample data above, but I need to create completely new node from scratch as well.
So, how can I add a new node into this tree using PHP function that efficients with large trees?