I have this table schema and data,I have no idea on how can I update all parentid 7,5 and 1 if there is new member added under parentid 7 example the newly added is 10.Then all his parentsid go up in the tree (Note: up to 10 parents only starting parentid 7 to go up in the tree can be updated there amount) 7,5 and 1 will be added amount to 500.
CREATE TABLE `mytree` (
`pid` INT(11) NOT NULL,
`memd` INT(11) NOT NULL,
`position` CHAR(1) NOT NULL,
`amount` DECIMAL(10,2) NOT NULL
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
;
pid memd position amount
0 1 1000.00
1 5 L 500.00
1 6 R 0.00
5 7 L 0.00
5 8 R 0.00
7 9 L 0.00
Here is my tree.
After added new member 10
pid memd position amount
0 1 1500.00
1 5 L 1000.00
1 6 R 0.00
5 7 L 500.00
5 8 R 0.00
7 9 L 0.00
7 10 R 0.00
EDIT IF the parent has no child yet then added a new one,the parent cannot recieve 500,or there is no update could be made in amount of parent.
EDIT latest problem
Problem if I have series of one child,then one of the children get paired.,it will only update the amount of his direct parent,the above parent of his parent etc.., did not updated, how can I update those his parent even it has only 1 child,example 9 and 10 should receive also amount because they are the parent of '11'
pid memd position amount
0 1 1500.00
1 5 L 1000.00
1 6 R 0.00
5 7 L 500.00
5 8 R 0.00
7 9 L 0.00
9 10 L 0.00
10 11 L 0.00
11 12 L 0.00
11 13 R 0.00
How can I achieve this.
Thank you in advance.