CodeIgniter Forums
Multi level menu from database section table - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Multi level menu from database section table (/showthread.php?tid=28506)



Multi level menu from database section table - El Forum - 03-13-2010

[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


Multi level menu from database section table - El Forum - 03-13-2010

[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);
    
    }
}