Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Site navigation using tree structure in database

    I was going to create the type of structure as outlined on these pages, but am wondering if anybody else is familiar with this concept, what it is called, and if there are any functions already written which I could make use of.



    By using Left and Right fields in the database, along with the ID and Parent ID, it makes it simple to select a branch of the tree from leaf to root with just one query ,http://conf2.php.net/show/top7-vancouver/22/

    Mainly, I think I am looking for a function which would arrange the Left and Right fields in the database in the proper numerical order.

    http://conf2.php.net/show/top7-vancouver/21/
    http://conf2.php.net/show/top7-vancouver/23/
    http://conf2.php.net/show/top7-vancouver/24/

  • #2
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you talking about how it shows up

    CodingForums.com > :: Server side development > PHP > Site navigation using tree structure in database

    Like that?

    That is called Modified Preordered Tree Traversal.

    It's a fairly simple concept. A great tutorial is here http://www.aesthetic-theory.com/show...torials&t=mptt
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, that'll do it

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is a function, and usage, I have written to order the preordered tree

    PHP Code:
    <?

    mysql_query
    ('UPDATE SiteNav SET left = NULL, right = NULL');

    echo (
    Circle());






    // call with no parameter
    // recursive function

    function Circle($siteNavID 1$number 1)
    {

    mysql_query('UPDATE DELAYED SiteNav SET `left` = '.$number.' WHERE siteNavID = '.$siteNavID);

    $query mysql_query('SELECT siteNavID FROM SiteNav WHERE parentID = '.$siteNavID.' ORDER BY name ASC');

    if (
    mysql_num_rows($query) > 0) {
        while (
    $row mysql_fetch_object($query)) {
            
    $number++;
            
    $number Circle($row->siteNavID$number);
        }
    }

    $number++;
    mysql_query('UPDATE DELAYED SiteNav SET `right` = '.$number.' WHERE siteNavID = '.$siteNavID);

    return (
    $number);


    }

    ?>


  •  

    Posting Permissions

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