Welcome Guest, Not a member yet? Register   Sign In
hierarchy system in mysql with php
#7

[eluser]FutureKing[/eluser]
Thank you very much.

One more thing I want to ask;

Please look at the code below:
Code:
function index()
    {
        $this->load->model('MPTtree');
        $this->MPTtree->set_opts(array( 'table' => 'orgchart',
        'left' => 'lft',
        'right' => 'rgt',
        'id' => 'catid',
        'title' => 'member'));
        $tree = $this->MPTtree->tree2array();    
        $this->doit($tree);
    }
    function doit($tree,$prev_text=''){                
        foreach($tree as $node){                        
            if($prev_text!=''){
                echo $prev_text.$node['member'];                
            }else{
                echo $node['member'];
            }
            echo "<br />";
            //echo $node['lft'].'<br />';
            
            if(isset($node['children'])){
                $prev_text=$prev_text.$node['member'].'--';
                $tree=$node['children'];
                $this->doit($tree,$prev_text);
            }
        }
        $prev_text='';        
    }

The above code generates the following output from tree2array() method:
albert
albert--A child!
albert--bert
albert--chuck
albert--chuck--donna
albert--chuck--eddie
albert--chuck--fred

I just want to ask, I am using $this->doit($tree,$prev_text); from doit() function.
Is it ok to call any function from inside of itself?

If not then Is there any alternative way to get the same output?


Messages In This Thread
hierarchy system in mysql with php - by El Forum - 06-05-2009, 03:09 AM
hierarchy system in mysql with php - by El Forum - 06-05-2009, 03:21 AM
hierarchy system in mysql with php - by El Forum - 06-05-2009, 04:11 AM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 12:59 PM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 01:01 PM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 01:08 PM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 03:22 PM
hierarchy system in mysql with php - by El Forum - 06-07-2009, 04:30 PM
hierarchy system in mysql with php - by El Forum - 06-08-2009, 06:40 AM
hierarchy system in mysql with php - by El Forum - 06-08-2009, 09:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB