[eluser]Krystian[/eluser]
ok, based on your previous advices
library, I used CI super object
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mymenu {
public function create_menu($parent, $level)
{
$CI =& get_instance();
$query = $CI->db->query("SELECT a.id id, a.label label, a.link link, Deriv1.Count 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>";
$menu .= $this->create_menu($position->id, $level + 1);
$menu .= "</li>";
}elseif($position->count == 0) {
$menu .= "<li><a >link . "'>" . $position->label . "</a></li>";
}else;
}
$menu .= "</ul>";
return $menu;
}
}
/* End of file Mymenu.php */
then in controller
Code:
$data['menu_header'] = $this->mymenu->create_menu(0, 1);
everything works fine. Thanks!
Why I get Undefined variable: menu ( this is not a problem, but why when I code in the first line var $menu = '' I get parse error ? and when $menu = '' not? all systems libraries have got var )