Welcome Guest, Not a member yet? Register   Sign In
tree menu & sub-menu using codeigniter
#1

Hey,

SQL structure of
----------------
id,parent_id_menu_name,link_id
-------------------------------
for Social -> Facebook, Google Plus
for Contact -> Email
How to fetch the menu that should represents their sub-menu?

here is the model class:

Code:
<?php
class Model_get extends CI_Model {

// Calling Menu
public function GetData() {
$query = $this->db->get_where('menu', array('parent_id' => 0));
return $query->result();
}

// Calling sub-menu
public function GetParent() {
$query = $this->db->get_where('menu', array('parent_id' => 0, 'id'=> 2));
return $query->result();
}

}

View:

Code:
    <div class="col-sm-9">

           <nav id="desktop-menu">
              <ul class="sf-menu" id="navigation">
             <?php
               foreach($results as $row) {
               $title = $row->menu_name;  ?>

                   <li><a href="#"><?php echo $title; ?></a>



                       <ul>
                              <?php foreach($results2 as $show) {
                                   $sub_menu = $show->menu_name; ?>


      <li><a href="index-video.html"><?php echo $sub_menu; ?></a></li>
      <?php } ?>
                         </ul>



<?php } ?>
 </li>
Reply
#2

You can find help here (note: is a tutorial of mine): http://avenir.ro/multi-level-unlimited-m...sub-menus/
It doesn't explain it for CodeIgniter, but it is the same principle. Give it a try.
Reply
#3

(04-02-2015, 01:11 PM)Avenirer Wrote: You can find help here (note: is a tutorial of mine): http://avenir.ro/multi-level-unlimited-m...sub-menus/
It doesn't explain it for CodeIgniter, but it is the same principle. Give it a try.

Could you explain this codes individually.

PHP Code:
function ordered_menu($array,$parent_id 0)
{
  
$temp_array = array();
  foreach(
$array as $element)
  {
    if(
$element['parent_id']==$parent_id)
    {
      
$element['subs'] = ordered_menu($array,$element['id']);
      
$temp_array[] = $element;
    }
  }
  return 
$temp_array;

Reply
#4

Could you please explain this code

Code:
function ordered_menu($array,$parent_id = 0)
{
  $temp_array = array();
  foreach($array as $element)
  {
    if($element['parent_id']==$parent_id)
    {
      $element['subs'] = ordered_menu($array,$element['id']);
      $temp_array[] = $element;
    }
  }
  return $temp_array;
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB