Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-10-2008, 03:45 AM   PM User | #1
o0O0o.o0O0o
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
o0O0o.o0O0o is infamous around these parts
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 it´s 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
o0O0o.o0O0o is offline   Reply With Quote
Old 12-10-2008, 04:22 AM   PM User | #2
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
echo out $parent and see what you get
masterofollies is offline   Reply With Quote
Old 12-10-2008, 04:52 AM   PM User | #3
o0O0o.o0O0o
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
o0O0o.o0O0o is infamous around these parts
i get 2
__________________
Please de-reputate me
© 0o0o0o0

Its better to rule in Hell then to serve in Heaven
o0O0o.o0O0o is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:01 AM.


Advertisement
Log in to turn off these ads.