tags:

views:

132

answers:

1

I am just puzzled here. Maybe because it's the end of the day, I dont know. Im using PHP to grab items from a MySQL db. I am just looking for some PHP help. I have the HTML and CSS done. Here is the basic structure of the db. Its a nested set btw. Imagine that my left and right values for the nested set have been sorted in MySQL already which leaves me with depth.

----------------------------------------
| id | title | sequence_number | depth |
----------------------------------------
| 1  | A     | 1               | 1     |
| 2  | B     | 2               | 1     |
| 3  | C     | 1               | 2     |
| 4  | D     | 3               | 1     |
| 5  | E     | 4               | 1     |
| 6  | F     | 2               | 2     |
| 7  | A     | 1               | 3     |
| 8  | B     | 5               | 1     |
| 9  | C     | 3               | 2     |
| 10 | D     | 2               | 3     |
| 11 | E     | 6               | 1     |
| 12 | F     | 4               | 2     |
----------------------------------------

Now if that's not enough to confuse you then keep reading. I am using a foreach loop to loop through each item and sort it manually like that. The problem is the menu eventually will go to 3 levels which gets me stuck as my loop is only for two levels. Can anybody help me sort this array?

A: 

you could use a recursive function

eg loop through with depth set as 1 then re-call the function with depth set as depth + 1

does that help? Josh

Josh