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 3 of 3

Thread: php tree help

  1. #1
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts

    php tree help

    hi ,


    I have copied this code to display the tree with ext js.
    but when i click on the folder then tree expands and give me again the same folder and so on. It does not give me its children

    here is the code


    PHP Code:
    class tx_taw_models_ProjectCategoryListProxy{
     
        
    /*
         * Load tree node.
         */    
         
    function getTree($TYPO3_db,$TYPO3_db_username,$TYPO3_db_password,$TYPO3_db_host,$node){
            
    $conn mysql_connect($TYPO3_db_host$TYPO3_db_username$TYPO3_db_password); 
            
    mysql_select_db($TYPO3_db$conn);
            
    $nodes $this->display_children($node);
            
    mysql_close($conn);
            print 
    json_encode($nodes);
        }
     
        
    // http://www.sitepoint.com/article/hierarchical-data-database
        // http://extjs.com/forum/archive/index.php/t-10082.html
        // $parent is the parent of the children we want to see
        // $level is increased when we go deeper into the tree,
        //        used to display a nice indented tree
     
        
    function display_children($parent) {
            
    // retrieve all children of $parent
            
    $result mysql_query(  'SELECT uid, upc_name, upc_parent, upc_order ' .
                                    
    'FROM tx_taw_user_project_category ' .
                                    
    'WHERE upc_parent = ' $parent ' ' .
                                    
                                    
    'ORDER BY upc_order;');
            
    // display each child
            
    while ($row mysql_fetch_array($result)) {
                
    // Response parameters.
                
    $path['text']        = html_entity_decode($row['upc_name']);
                
    $path['id']            = $row['uid'];
                
    $path['position']    = $row['upc_order'];
                
    // Check if node is a leaf or a folder.
                
    $cResult mysql_query'SELECT uid, upc_name, upc_parent, upc_order ' .
                                        
    'FROM tx_taw_user_project_category ' .
                                        
    'WHERE upc_parent = ' $row['uid'] . ' ' .
                                    
                                        
    'ORDER BY upc_order;');
                
    $cCount mysql_num_rows($cResult);
                if(
    $cCount 0){
                    
    $path['leaf']    = false;
                    
    $path['cls']    = 'folder';
                }else{
                    
    $path['leaf']    = true;
                    
    $path['cls']    = 'file';
                }
     
                
    // call this function again to display this
                // child's children
                
    $nodes[] = $path;
            }
            return 
    $nodes;
        }
     
     
    }


    $treeDataModel = new tx_taw_models_ProjectCategoryListProxy;
    $node =  ;//$_POST['node'];
    if ($node == 0){                  // < if its the first node
      
    $node 1// Initial node.
    }
    $treeDataModel ->getTree('testdb','root','','localhost'$node); 
    Please de-reputate me
    0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    echo out $parent and see what you get

  • #3
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    i get 2
    Please de-reputate me
    0o0o0o0

    Its better to rule in Hell then to serve in Heaven


  •  

    Posting Permissions

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