Debt Consolidation - Sportingbet - Wordpress Themes - Article directory - Debt Consolidation

PDA

View Full Version : Category Three How


PinoyIto
Dec 6th 2006, 9:58 pm
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

Thanks in Advance

smallbuzz
Dec 6th 2006, 10:11 pm
Its called a hierarchical sql.
Similar to this http://www.onlamp.com/pub/a/onlamp/2004/08/05/hierarchical_sql.html

Yeldarb
Dec 6th 2006, 10:13 pm
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);
}
}
}


Should work.. I think.

Edit: I forgot to build in the tabbing though. You'll have to do that.

PinoyIto
Dec 6th 2006, 11:28 pm
Its called a hierarchical sql.
Similar to this http://www.onlamp.com/pub/a/onlamp/2004/08/05/hierarchical_sql.html

Thanks for the link man...