Welcome Guest, Not a member yet? Register   Sign In
Creating dynamic dropdown menu system
#1

[eluser]MarceloTM[/eluser]
Hello everyone, I'm trying to make a dynamic menu system that builds the menu itens according to the user access level on the site. I've made the initial query to get the parent menu option, but I don't know how to add another array with the options of every menu item... I've got the following code so far:

$menus = $this->db->query($query_str, $idacesso);

if($menus->num_rows() > 0){
foreach($menus as $menu){
// Now what?
}
}

Can I add the query for the menu options inside the foreach loop, filtering by the menu id?
Any help will be very appreciated.
Thanks.
#2

[eluser]Basketcasesoftware[/eluser]
How is your database structured? How does your access level system work? A query essential builds an array for you without extra outside looping. I don't mind helping but I need more information as to what you are trying to accomplish.
#3

[eluser]Pegasus275[/eluser]
let's assume that you have

id int
mnu_id id of parent menu
menu_name
url menu_url
etc...

you need to create function. the recursive function

for example

function my_menu($root_id)//0 for rootSmile
{
$menus = $this->db->query("select * from my_menu where mnu_id=$root_id");
if($menus->num_rows() > 0){
foreach($menus->result() as $menu){
$data['menu_id_'.$root_id] = array($menu->id,$menu->name,$menu->url,$menu->etc);
$data['menu_id_'.$root_id.'_child'] = my_menu($menu->id);
}
}
return $data;
}

You will get array of menu items you defined, note: this is just exampleSmile




Theme © iAndrew 2016 - Forum software by © MyBB