Welcome Guest, Not a member yet? Register   Sign In
Multi level menu from database section table
#1

[eluser]Aljebrini[/eluser]
hello,

I have section table stored in database, each section have an [ ID, Title, ParentID ]
ID : for section id
Title : Section name
ParentID : For parent section ID .


this would give me tree hierarchy, what i aim to do is to get the hole sections from the database and put it in Multilevel menu ..

Code:
Private $Sections = null ; // this is class member

function _Sections($root){
        
        $this->db->select('id,Name,Parent_ID,MenuTitle');
        $this->db->Where('Parent_ID',$root);
        $this->db->Where('IsActive','Y');
        $query = $this->db->get('sections');
        foreach ($query->result() as $row)
            {
              $this->Section[] = $row->Title;
              $this->_Sections($row->id);

            }
        
        
        $query->free_result();
        
    }

    
function sectionsTree(){
        
        $this->_Sections(0);
        return $this->Section();
    }

but i still haven't the desired values Smile
#2

[eluser]Aljebrini[/eluser]
that's will work successfully Now Smile
take a look


Code:
Class Section Extends Model {

    private $Section = array();
    
    function Section() {
    
            parent::Model();
                        }
    function _Sections($root){
        
        $this->db->select('id,Name,Parent_ID,MenuTitle');
        $this->db->Where('Parent_ID',$root);
        $this->db->Where('IsActive','Y');
        $query = $this->db->get('sections');
        $this->Section[] = '<ul>';
        foreach ($query->result() as $row)
            {
                $this->Section[] = '<li>';
              $this->Section[] = anchor('site/section/'.$row->id,$row->Name);
              $this->_Sections($row->id);
             $this->Section[] = '</li>';
            }
        $this->Section[] = '</ul>';
        
        $query->free_result();
        return $this->Section;
    }

    
function sectionsTree(){
        
            return $this->_Sections(0);
    
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB