whitesox99
MIS
Hi,
I need to create a tree structure from a resultset and show them into my JSP. Here is my table sql (grup).
What I really need is a recursive method to search for all the children of each row and build a tree heirarchy. e.g. the data may look like
So looking at the top data my final tree structure should look like
and so on. ORDER_BY show the order in which each element should display in the heirarchy. I am really struggling to find a way on how to have the heirarchy built and really need some help.
Thanks
Here is the SQL i have to het the data
I need to create a tree structure from a resultset and show them into my JSP. Here is my table sql (grup).
Code:
CREATE TABLE GRUP (
ID_GRUP int(11) NOT NULL default '0',
ID_GRUP_PARENT int(11) NOT NULL default '0',
ORDER_BY int(11) NOT NULL default '1',
DESCRP varchar(100) default NULL,
PRIMARY KEY ('ID_GRUP'),
)
What I really need is a recursive method to search for all the children of each row and build a tree heirarchy. e.g. the data may look like
Code:
ID_GRUP ID_GRUP_PARENT ORDER_BY DESCRP
1 0 1 It itself is the parent
2 1 1 It's Parent is ID_GRUP=1
3 0 2 It itself is the parent
4 2 1 It's parent is ID_GRUP=2
5 1 2 It's Parent is ID_GRUP=1
6 4 1 It's Parent is ID_GRUP=4
7 2 2 It's parent is ID_GRUP=2
8 2 3 It's parent is ID_GRUP=2
So looking at the top data my final tree structure should look like
Code:
1
2
4
6
7
8
5
3
Thanks
Here is the SQL i have to het the data
Code:
SELECT ID_GRUP, ID_GRUP_PARENT, DESCRP FROM GRUP ORDER BY ORDER_BY.