Welcome Guest, Not a member yet? Register   Sign In
Running a db query then running another query
#5

[eluser]the future darlo manager[/eluser]
Right I've been trying to think about this but don't think I'm any closer to solving it.

I have two models (one for my menu groups and one for the sub menu navigation).

Code:
class Menu_groups_model extends Model{
    
    function Menu_groups_model() {
        parent::Model();
    }
    
    function getMainNav() {
        $query = $this->db->query("SELECT *
        FROM nrcpd_menu_groups WHERE display_on_site = 'Y'
        ORDER BY list_order");
        return $query;
    }
    
}

Code:
class Sub_navigation_model extends Model{
    
    function Sub_navigation_model() {
        parent::Model();
    }
    
    function getSubNav($group_id) {    
        $query = $this->db->query("SELECT *
        FROM nrcpd_sub_navigation
        WHERE group_id = $group_id
        ORDER BY List_order
        ASC");
        return $query;
    }
    
}

I also have my sitemap function in controller....

Code:
function sitemap()
    {
        //Loads the query to construct the navigation and sub navigation
        $data['top_level_links'] = $this->Menu_groups_model->getMainNav();
        
        foreach ($data['top_level_links']->result() as $row)
        {
            $data['sub_level_links_for_$row->group_id'] = $this->Sub_navigation_model->getSubNav($row->group_id);
        }
        
    }

Basically I want to end up with something like this below...

Main navigation link no 1
-Sub navigation for that group
-Sub navigation for that group
Main navigation link no 2
-Sub navigation for that group
-Sub navigation for that group

Obviously I need to loop through each of the main group records to get my top links. This will give me the correct order they are in (list_order sort) and then loop through the sub navigation ones. However this is where I am getting unstuck. I think I need to put all the sub navigation records into one big array so I can work with them in the view but I'm not too sure how to do it.

This is probably the trickiest thing I've done yet in CI. Nothing has caused me this much grief.


Messages In This Thread
Running a db query then running another query - by El Forum - 03-03-2009, 07:51 AM
Running a db query then running another query - by El Forum - 03-03-2009, 07:59 AM
Running a db query then running another query - by El Forum - 03-03-2009, 08:08 AM
Running a db query then running another query - by El Forum - 03-03-2009, 08:16 AM
Running a db query then running another query - by El Forum - 03-04-2009, 07:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB