php menu and submenu to array
What I would like to accomplish:
$config['navigation'] = array(
"Home" => "",
"Item 1" => array("page1", array()),
"Item 2" => array("subpages", array(
"Item 2.1" => "subpages/page1",
"Item 2.2" => array("subpages/page2", array()),
"Item 2.3" => "subpages/page3",
)),
"Item 3" => "another_page",
"Contact Us" => array("contact_us", array()),
);
My MySql table looks something like this:
id | name | ur开发者_如何学Cl | parent
If parent is filled in the item is a submenu which belongs to the corresponding id.
How should my select statement and loop look like? I would like to achieve a minimum of code for max result.
Thanks in advance..!
Something like this may work ...
select id,name,url,parent from tbl group by parent order by id asc
However, the problem you are going to run into if the parent child relationship is editable is the ordering of the menu .. what comes after home and before contact us, you may need another column called order and that could be used to order the children of any given parent
精彩评论