SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Parent/child - structure (?)

    Hi,

    I have a table with different groups... (seen it before? )

    I have a lookuptable with the fields parent and child

    Let's say group 1 is top level

    Group 2, 3, 4 are children of group 1

    5, 6 are children of group 2

    7, 8, 9, 102 are children of group 3

    22 is child of group 4

    I've thought about this for a while, but could some of you help me by pointing me in the right direction?

    Is it possible that any group can only have one parent, but also some kind of cross-structure?

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right direction == opposite of left direction ?

    What's the thing you need help with?

    I think you have the correct table fields;
    id, blah, blah, parent_id
    ...and parent_id is null or 0 for the top group
    ...and when you need all children of group N you...
    select x, y, z
    from blah
    where parent_id = N

    Of course each group could have two or more parents, e.g.
    id, blah, blah, father_id, mother_id

    (seen it before? )

  3. #3
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does that mean that I don't need the lookuptable?

    What if I want to display the whole hierarchy tree?

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

  6. #6
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, here is a post I made the other day there in relation to XML, though it uses parent -> child nodes as you require.

    There is a complete script there waiting for you - it'll get you started in no time at all.

    Look at:

    http://www.sitepointforums.com/showt...threadid=95684

  8. #8
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And here's the definitive way to tackle it in SQL Server 2000 (it might work in v7 too)....
    http://msdn.microsoft.com/library/de...qd_14_5yk3.asp
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  9. #9
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by M@rco
    And here's the definitive way to tackle it in SQL Server 2000 ...
    Very good example
    But this part;
    "SELECT @line = space(@lvl - 1) + @current
    PRINT @line", is kind of unsatisfactory
    Most of the time you want to print out some icons, instead of just spaces (or dots), and also use a different icon ("L" style) for the last child node

    Anyway; found this cool tool:
    iNavigate Tree Menu Generator
    (Haven't tested, just thought it looked useful)


    BTW, did you know that there's a bug(?) in the replicate() function; if the table has a different collation than the database, then, for example, replicate(' ', 10) returns only one(1) ' ' (!)
    Maybe the same thing happens to the space() function?
    Have to test...

    Edit: here's the test results
    Last edited by jofa; Feb 22, 2003 at 04:36.

  10. #10
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by jofa
    Very good example
    But this part;
    "SELECT @line = space(@lvl - 1) + @current
    PRINT @line", is kind of unsatisfactory
    Most of the time you want to print out some icons, instead of just spaces (or dots), and also use a different icon ("L" style) for the last child node
    Yeah, I agree. I'd just return the depth of the node in the hierarchy instead of that bit, and do the rest in ASP/JavaScript as appropriate.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •