views:

25

answers:

1

I'm trying to select a node in my heirarchical system.

I have the "/Path/To/Some/Node" (In exactly that form) and I am trying to figure out how I can get the children of "Node". Naturally "Node" is pseudo-unique, in that it is the only child called "Node" inside of Some, but there could be another "Node" inside of "Path" so you obviously can't just explode and then do a simple Node.

So I need to create a select query which looks down each level...

I could obviously do this by using tonnes of querys, ie.

Select id from Table where name = "Path"
Select id from Table where name = "To" and parent = "$id"
Select id from Table where name = "Some" and parent = "$id"
Select id from Table where name = "Node" and parent = "$id"

This isn't ideal... Can anyone advise?

A: 

This article might help:

You could extend it to add the "path" column like you mentioned to select original node. Then using a single additional query (as described in the article), you could grab the rest of the nodes in the path.

konforce
I've read a lot of all of the top articles on this topic that I can find, along with that article unfortunately... I think adding a "path" column is going to be the best way of doing it.
Laykes
I think I might just force all 'Nodes' to have unique names wether they are at the root or a 10th child. It just simplifies this problem massively. Since I am lazy loading my structure, I don't want to have to make 10 queries or create a recursive query. I'm also not sticking to a arbitrary length.Maybe someone else knows a good way.
Laykes