I am trying to display a category three of my site, but I am having problem doing it. I heard that this can be accomplish in single sub query string.... I hope I can get help from here... Here are some example of my data ID CATEGORY_NAME PARENTID 1 Philippines 0 2 Abra 1 3 Bataan 1 4 Abucay 3 5 Balanga 3 6 Bangued 2 7 Pilar 3 8 Pilar 2 9 Bayan 7 I want to output them in tree format like this Philippines |__Abra | |___Bangued | |___Pilar |__Bataan |__Abucay |__Balanga |__Piliar |__Bayan Code (markup): Thanks in Advance
Its called a hierarchical sql. Similar to this http://www.onlamp.com/pub/a/onlamp/2004/08/05/hierarchical_sql.html
Looks like a good job for a recursive function Psuedocode: yourFunction(array, 1); yourFunction(array, int parent) { for(int i=0; i<array.length(); i++) { if(array[i].parent == parent) { echo array[i].name; yourFunction(array, array[i].id); } } } Code (markup): Should work.. I think. Edit: I forgot to build in the tabbing though. You'll have to do that.