Phillip B Oldham writes "Hi.I'm having problems with a single table which is used to output a list of folders in a tree format.I have a table similar to the following:-------------------------+ id + folder + parent +-------------------------+ 0 + Root + 0 ++ 1 + Folder1 + 0 ++ 2 + Folder2 + 0 ++ 3 + Sub1 + 2 ++ 4 + Folder3 + 0 ++ 5 + Sub2 + 2 +-------------------------
What I'm looking to get is the following:Table:------------------------+ parent + child +------------------------+ Root + Root ++ Root + Folder1 ++ Root + Folder2 ++ Folder2 + Sub1 ++ Folder2 + Sub2 ++ Root + Folder3 +------------------------Structure:+Root +Folder1 +Folder2 +Sub1 +Sub2 +Folder3
I'm using the following SQL Statement, which is working in so far as its pulling the information out of one table:SELECT p.folder AS parent, c.folder AS childFROM table AS p, table AS cWHERE p.id = c.parent;
But what I'm getting is the following:Table:------------------------+ parent + child +------------------------+ Root + Root ++ Root + Folder1 ++ Root + Folder2 ++ Folder2 + Sub1 ++ Root + Folder3 ++ Folder2 + Sub2 +------------------------Structure:+Root +Folder1 +Folder2 +Sub1 +Folder3 +Sub2
I've tried to order by id, but it throws the ordering out completely, with Folder2 (+subfolders) coming after Folder3.Can you help me please?Thanks!"