INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Create a tree from a resultset

Create a tree from a resultset

(OP)
Hi,

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
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

CODE

SELECT ID_GRUP, ID_GRUP_PARENT, DESCRP FROM GRUP ORDER BY ORDER_BY.
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close