I am having trouble with the syntax for my query and again it may be due to my lack of knowledge of JOIN's which is steadily improving.
Here is the singular version of the INSERT query I am trying to iterate multiple times based on the result of another query.
INSERT INTO sch_nested_parts
(component_tree_id, part_id, lft, rgt, dependency)
SELECT $parentTreeId, part_id, lft+1, rgt+1, $childTreeId
FROM sch_nested_parts
WHERE component_tree_id = $childTreeId
The value $parentTreeId is where the FOR EACH exists, for want of a better phrase. Rather than being a single tree to insert into there are multiple.
I want to insert multiple times based on:
SELECT component_tree_id
FROM sch_nested_parts
WHERE dependency = (
SELECT component_tree_id
FROM sch_nested_parts
WHERE part_id = $childId AND lft = 1
)
This will mean for every tree that contains the child we are adding I will insert the sub parts of that child with a few tweaked values.
I am sorry if I have made things a little confusing but I am happy to clarify any areas where I have been unclear. This is a modification of the nested set model to allow for multiple parents.