Welcome Guest, Not a member yet? Register   Sign In
my own helper creating menu
#17

[eluser]Krystian[/eluser]
ok, try to not hate me Smile

look I don`t know how to use your tips and try to do this in model just for test with html tags

model
Code:
function getMenu($parent, $level)
    {
        
        $query = $this->db->query("SELECT a.id id, a.label, a.link, Deriv1.Count FROM `menu` a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" . $parent);

        $menu .= "<ul id='nav'>";

          
        foreach($query->result() as $position)
        {
            if($position->Count > 0) {
                
                $menu .= "<li><a >link . "'>" . $position->label . "</a>";

                    $this->getMenu($position->id, $level + 1);

                $menu .= "</li>";
                
            }elseif($position->Count == 0) {
            
                $menu .= "<li><a >link . "'>" . $position->label . "</a></li>";
                
            }else;

            }

           $menu .= "</ul>";
          
           return $menu;
    }

in controller
Code:
$data['menuHTML'] = $this->menu_model->getMenu(0, 1);
        
$this->load->view('main_view', $data);

in view simple echo $menuHTML

and it seems like recursive function is not working because I get only the first level.
And notice undefined var menu ;/;/
BUT of course I would like to do in helper


Messages In This Thread
my own helper creating menu - by El Forum - 08-13-2011, 07:05 AM
my own helper creating menu - by El Forum - 08-13-2011, 10:37 AM
my own helper creating menu - by El Forum - 08-13-2011, 11:25 AM
my own helper creating menu - by El Forum - 08-13-2011, 12:04 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:10 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:14 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:23 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:42 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:51 PM
my own helper creating menu - by El Forum - 08-13-2011, 01:17 PM
my own helper creating menu - by El Forum - 08-13-2011, 01:33 PM
my own helper creating menu - by El Forum - 08-13-2011, 07:06 PM
my own helper creating menu - by El Forum - 08-14-2011, 02:31 AM
my own helper creating menu - by El Forum - 08-14-2011, 04:04 AM
my own helper creating menu - by El Forum - 08-14-2011, 05:53 AM
my own helper creating menu - by El Forum - 08-14-2011, 06:28 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:11 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:34 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB