SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 28 of 28
  1. #26
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    sorry, i didn't read your post too clearly there. did you apply the rebuild_tree function yet? you need to do that to renumber your lt and rt columns before dispaly will work and before you can use the > and < where clauses to find parents.

  2. #27
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by designationlocut
    No I think it might be your database connection, you need to define it within the function.

    If a species doesn't have any children, then child_id is null as you are at the bottom of the tree. You start there, and them work your way backwards until the parent_id is null (at the top of the tree).
    Actually, my database connection is automatically included on all my pages. If I replace the recursive display script with

    PHP Code:
    $res mysql_query ("SELECT * FROM gzmammals1 WHERE NMammals = 2000"); 
    ...it works fine.

  3. #28
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by longneck
    sorry, i didn't read your post too clearly there. did you apply the rebuild_tree function yet? you need to do that to renumber your lt and rt columns before dispaly will work and before you can use the > and < where clauses to find parents.
    Wow, his instructions are confusing. I guess the script I was playing with was just another demonstration?

    Anyway, I found the "rebuild_tree" script on the third page. I decided to display everything within the order Carnivora, so I adapted it as follows:

    PHP Code:
    function rebuild_gzmammals1($parent$left) {
       
    // the right value of this node is the left value + 1
       
    $right $left+1;

       
    // get all children of this node
       
    $result mysql_query('SELECT Name FROM gzmammals1 '.
                              
    'WHERE Carnivora="'.$parent.'";');
       while (
    $row mysql_fetch_array($result)) {
           
    // recursive execution of this function for each
           // child of this node
           // $right is the current right value, which is
           // incremented by the rebuild_tree function
           
    $right rebuild_gzmammals1($row['Name'], $right);
       }

       
    // we've got the left value, and now that we've processed
       // the children of this node we also know the right value
       
    mysql_query('UPDATE gzmammals1 SET lt='.$left.', rt='.
                    
    $right.' WHERE Name="'.$parent.'";');

       
    // return the right value of this node + 1
       
    return $right+1;

    Again, my table is named gzmammals1, and I use "Name" instead of "title." To search for entries within Carnivora, I assume I change parent="'.$parent.'";') to Carnivora="'.$parent.'";')

    The instructions say,

    This is a recursive function. You should start it with rebuild_tree('Food',1); The function then retrieves all children of the ‘Food’ node.
    I assume that means change rebuild_gzmammals1($parent, $left) to rebuild_gzmammals1('Carnivora',1), but that gives me this error message:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '&' or T_VARIABLE in C:\sites\GeoZoo\public_html\practice\tab_ani.php on line 211


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
  •