SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with tree design

    Hi all,
    I've to develop a multilevel marketing web app. In this Im facing an issue, please help me in this issue

    MemberX
    \/
    child1 child2 child3 child4 child5 child6 child7
    \/
    child11 child22 child33 child44 child55 child66 child77

    each child can have 7 childs and upto 7 levels.

    my table design is as following

    tree
    -----

    id
    parent_id
    position
    level


    id | parent_id | position | level
    ---------------------------------
    2 | 1 | 0 | 1
    3 | 1 | 1 | 1
    4 | 1 | 2 | 1
    5 | 1 | 3 | 1
    6 | 2 | 1 | 1


    My problem is how to find a vacant position for given parent.

    eg: when member 2 (id=2) is adding a new member i've to add the new member 7 in to a vacant position
    under him or under any of his descendants.
    Is there any way find a vacacnt position ? Or any alternate database design for this purpose ?
    Pls help...

    Thanks & regards

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,000
    Mentioned
    101 Post(s)
    Tagged
    0 Thread(s)
    Have a read of this SitePoint Article:

    http://www.sitepoint.com/hierarchical-data-database/

    It discusses two methods of storing hierarchical data in a relational database
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


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
  •