Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

whitesox99 (MIS) (OP)
28 Mar 10 9:12
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.
 
prosper (Programmer)
28 Mar 10 22:33

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!

Back To Forum

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