开发者

php menu and submenu to array

开发者 https://www.devze.com 2023-03-11 02:35 出处:网络
What I would like to accomplish: $config[\'navigation\'] = array( \"Home\" => \"\", \"Item 1\" => array(\"page1\", 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号