[eluser]CodeIgniterNoob[/eluser]
I have two tables.
Table 1: parent_menu_item fields(parent_menu_id, parent_name)
Table 2: child_menu_item fields(child_menu_id, child_name, parent_menu_id)
I need to pull the parent and all the children that might to belong to the parent by parent_menu_id. So it has to look like this:
ParentMenuItem1
Childmenu
Childmenu
Childmenu
ParentMenuItem2
Childmenu
Childmenu
Childmenu
And so on.....
Heres my query so far:
Code:
function getAllParentAndChildMenuItems()
{
$data = array();
$this->db->join('parent_menu_item AS b', 'a.parent_menu_id = b.parent_menu_id', 'inner');
$this->db->where('b.status','active');
$this->db->order_by('b.sortorder','desc');
$this->db->order_by('a.sortorder','desc');
$this->db->select('b.*');
$this->db->select('a.*');
$Q = $this->db->get('child_menu_item AS a');
if ($Q->num_rows() > 0)
{
foreach ($Q->result_array() as $row)
{
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
And heres my view so far:
Code:
if (count($menu)) {
foreach ($menu as $key => $list) {
echo $list['parent_name']."<br />";
if ($list['parent_menu_id'] = $list['parent_menu_id']) {
echo $list['name']."<br />";
}
}
}
Can someone help me with this?