SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Post Assistance with Putting Together Heirarchy of Projects

    I'm trying to put together a project management system built with PHP and MySQL. Included in this CRM will be the ability to make certain projects children of other projects. For instance:

    Project 1 (parent of project 2 and project 3)
    Project 2 (child of project 1)
    Project 3 (child of project 1 and parent of project 4)
    Project 4 (child of project 3)
    My database currently is very simple in that my "Projects" table has a column for the Parent_Pjt ID number. This I expect to be expanded upon. My real question is how to go about building the query and array to display these projects?

    My initial though is to have a while() loop to display the list of the first level of projects. Then inside of that while loop I would have another while loop to display the second level of projects. However, I don't know how many levels deep to build the code as projects should be able to be related as many levels deep as necessary.

    Anyone have some simple ideas as to how I might be able to accomplish this?
    TAKE A WALK OUTSIDE YOUR MIND.

  2. #2
    Maniacally depressed robot poncho's Avatar
    Join Date
    Dec 2004
    Location
    Belfast, N.Ireland
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will find a great article on the Sitepoint website about storing hierarchial data in a database. Be aware that the method you have chosen (adjacent list) can have performance issues depending on the level of complexity. I have just used this method for an image gallery system and it can be a bit slow at times. I would seriously consider the "Modified Preorder Tree Traversal" if the relationships are going to be any more complex than your example above.

    Cheers;
    Poncho
    Perfecting the art of breaking stuff.
    Check 'em: CakePHP | TextMate


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
  •