php - How to implemente a menu with 2 levels codeigniter -


i'm trying implement menu 2 levels , categories programs ; example : parent 1: news 1.1:local 1.2:international

enter image description here

my problem after every click values change same category ..i hope u understand & sorry bad english :)

after 1 click : enter image description here

after 2sd click on same item: enter image description here

here code

model

public function get_categories($parent_id) {     return $this->db->select('id,parent_id,category_title_fr,category_title_ar,categorie_trie')                     ->from($this->table_categories)                     ->where('parent_id', $parent_id)                     ->order_by('parent_id')                     ->get()                     ->result(); }  public function get_categorieschild() {     return $this->db->select('id,parent_id,category_title_fr,category_title_ar,categorie_trie')                     ->from($this->table_categories)                     ->where('parent_id','0')                     ->get()                     ->result(); } 

controller

    $data['cat_niveau1'] = $this->listeprogram->get_categorieschild();     $this->load->view('templates/ar/template', $data); 

view

foreach ($cat_niveau0 $cat0) {     echo '<li><a href="'.base_url().'index.php/program/programme_chaine_ar/'.$cat0->id.             '" class="menu-button menu-drop"><span class="menu-label">'.$cat0->category_title_ar.'</span></a>';     echo '<div class="menu-dropdown menu-dropdown1"><ul class="menu-sub">';     foreach ($cat_niveau1 $cat1) {         if ($cat0->id == $cat1->parent_id) {             echo '<li><a href="'.base_url().'index.php/program/programme_chaine_ar/'.$cat0->id.'/'.$cat1->id.                     '" class="menu-subbutton"><span class="menu-label">'.$cat1->category_title_ar.'</span></a></li>';         }     }     ?>     <?php         echo '</ul></div></li>'; } 

first, don't see passing cat_niveau0. then, should either create data both levels in controllers , pass multidimentional associative array, or pass cat_niveau0, in view

foreach ($cat_niveau0 $cat0) { # $cat1 = # array through model based on cat0  } 

note: have strange names models: 1 get_categories should get_categorieschild , viceversa, maybe your're getting little mixed which :)


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -