php 菜单和子菜单数组
我想要完成的事情:
$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()),
);
我的MySql表看起来像这样:
id | name | url | parent
如果填写了父项,则该项目是属于相应id的子菜单。
我的 select 语句和循环应该是什么样子?我想用最少的代码获得最大的结果。
提前致谢..!
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 | url | 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..!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西可能会起作用...
但是,如果父子关系是可编辑的,您将遇到的问题是菜单的排序..在回家之后和联系我们之前,您可能需要另一个名为 order 的列和可用于对任何给定父母的孩子进行排序
Something like this may work ...
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