PHP Zend 框架 - 多层菜单

发布于 2024-10-16 11:22:58 字数 342 浏览 6 评论 0原文

在我的应用程序中,我想制作一个像这样的动态多层菜单

玩具1

==>子玩具1-a

==>子玩具1-b

玩具2

==>子玩具2-a

==>子玩具2-b

玩具3

==子玩具3-a

我在数据库中创建了 2 个名为parent的表-菜单包含Toy1,Toy2,Toy3,子菜单包含Sub toy1-a,Sub toy1-b及其所属的父级。我不知道如何检索数据库或算法来实现此目的。有人有解决办法吗?

In my application, i want to make a dynamic multi layer menu like this

Toy1

==>Sub toy1-a

==>Sub toy1-b

Toy2

==>Sub toy2-a

==>Sub toy2-b

Toy3

==Sub toy3-a

I have created 2 table in database called parent-Menu contain Toy1,Toy2,Toy3 and sub-Menu contain Sub toy1-a, Sub toy1-b and their father which it belongs. I don't know how to retrieve database or algorithm to make this. Anybody have solution ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最初的梦 2024-10-23 11:22:59

我建议您只使用一张表,这将使您的程序变得非常容易。

为所有顶部菜单取 3 个字段 *menu_id* 、 *menu_text* 、 *parent_id* 取父 id 1。现在执行以下工作,

从表中检索所有数据。

并使用递归函数来放置菜单。

I can recommend you to use only one table, it will make your program very eaisy.

take 3 field *menu_id* , *menu_text* , *parent_id* for all top menu take parent id 1. now do the following work,

Retrieve all data from the table.

And use the recursive function to the place the menu.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文