I don't know if I have been working for too long today but for some reason I can't seem to get my head around a particular problem. I have a set of data which is hierarchical in nature, and which I need to display as such - but there is not a set structure. For example, it may be something like this:

Code:
1. Level 1 Text
2. Level 1 Text
  a. Level 2 Text
  b. Level 2 Text
    i) Level 3 Text
    ii) Level 3 Text
  c. Level 2 Text
3. Level 1 Text
Basically I am calling a row of data from the first level by ID (so either 1, 2 or 3 in the example) and need to also fetch its children so I can display it as I have shown for that particular piece of data. My current means of arranging the data is:
Code:
id | text | parent_id (default=NULL)
I am only starting on this particular project so if this is not the best way to structure the data I am open to suggestion.

I'm stuck for a way to loop through the data and return it in such a way that makes traversing it relatively easy for the purposes of display and analysis, given that a given data entry may not have children and has a variable number of children.

I'm not sure if I've made myself clear or not so I can clarify if needs be. My brain is fried at this point and I can't seem to think logically around this issue.