I'm creating a dynamic navigation menu on Codeiginter which retrieve from MYSQL DB Here is the description of navigation
Parent table
|---parent_id---link---title-----|
|---1-----------#------Parent1---|
|---2-----------#------Parent2---|
|---3-----------#------Parent3---|
Children table
|---children_id---fk_parent_id---title-------|
|--------1---------2-------------children1---|
|--------2---------2-------------children2---|
|--------3---------2-------------children3---|
Sub Children table (This sub child will show when children was selected)
|---sub_child_id--- fk_children_d ------title-------|
|------1--------------2-------------Sub Children1---|
|------2--------------2-------------Sub Children2---|
|------3--------------2-------------Sub Children3---|
Navigation menu
|---------|---------|--------|
| Parent1 |Parent2 |Parent3 |
|---------|===++====|--------|
|=============++======================================|
|---|Children1|-----|Children2|-----|Childrent3|------|
|-===================++===============================|
|-----------------|Sub Childrent1|--------------------|
|-----------------|Sub Childrent2|--------------------|
|-----------------|Sub Childrent3|--------------------|
Notes: As my below code it work only on Children but it don't show on sub Children
Here is my model function which to create some conditional for childrent and parent
function menu() {
$this->db->select("*");
$this->db->from("menu_parents");
$q = $this->db->get();
$final = array();
if ($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$this->db->select("*");
$this->db->from("menu_childrent");
$this->db->where("fk_p_id", $row->parents_id);
$q = $this->db->get();
if ($q->num_rows() > 0) {
$row->children = $q->result();
foreach ($q->result() as $srow){
//This is the session problem which I want to select for my sub children from menus_children
$this->db->select("*");
$this->db->from("menu_sub_childrent");
$this->db->where("fk_m_child_id", $srow->m_child_id);
$q = $this->db->get();
if($q->num_rows()>0){
$row->sub_children = $q->result();
}
}
}
array_push($final, $row);
}
}
return $final;
}
Here is my view
<ul class="nav navbar-nav">
<?PHP foreach($menus as $menu): ?>
<li class="dropdown megamenu-fullwidth">
<a data-toggle="dropdown" class="dropdown-toggle" href="#"> <?PHP echo $menu->title;?> <?PHP if(isset($menu->children)):?><b class="caret"></b><?PHP endif;?></a>
<?PHP if(isset($menu->children)):?>
<ul class="dropdown-menu">
<?PHP foreach($menu->children as $child): ?>
<li class="megamenu-content">
<ul class="col-lg-2 col-sm-2 col-md-2">
<li class="no-border"><p><strong><?PHP echo $child->title;?></strong></p></li>
<?PHP if(isset($menu->sub_children)):?>
<?PHP foreach($menu->sub_children as $sub_children): ?>
<li><a href="#"> <?PHP echo $sub_children->title; ?><br></a></li>
<?PHP endforeach; ?>
<?PHP endif;?>
</ul>
</li>
<?PHP endforeach; ?>
</ul>
<?PHP endif; ?>
</li>
<?PHP endforeach; ?>
</ul>
Here is i Use Var_dump()
array (size=3)
0 =>
object(stdClass)[22]
public 'parents_id' => string '1' (length=1)
public 'linke' => string '' (length=0)
public 'title' => string 'parent1' (length=7)
1 =>
object(stdClass)[23]
public 'parents_id' => string '2' (length=1)
public 'linke' => string '' (length=0)
public 'title' => string 'parent2' (length=7)
public 'children' =>
array (size=6)
0 =>
object(stdClass)[26]
...
1 =>
object(stdClass)[25]
...
2 =>
object(stdClass)[27]
...
3 =>
object(stdClass)[28]
...
4 =>
object(stdClass)[29]
...
5 =>
object(stdClass)[30]
...
public 'sub_children' =>
array (size=1)
0 =>
object(stdClass)[33]
...
2 =>
object(stdClass)[24]
public 'parents_id' => string '3' (length=1)
public 'linke' => string '' (length=0)
public 'title' => string 'parent1' (length=7)
Thanks advance for your help Sir

