Re: Best practice for creating mysql database structure for menus navigation
| From: | Torsten Roehr | Date: | Mon, 19 Apr 2004 13:39:34 +0000 |
| Subject: | Re: Best practice for creating mysql database structure for menus navigation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-183802@lists.php.net to get a copy of this message | ||
"Dr. Zoidberg" <php@1203.qwe.uni.cc> wrote in message
news:4083D2A7.4080100@1203.qwe.uni.cc...
> Hello,
>
> What will be the best database structure for creating web site
> navigation, menus with submenus (unlimited levels).
I'd suggest 2 id columns:
CREATE TABLE menu (
menuItemID int(11) NOT NULL auto_increment,
parentMenuItemID int(11) NOT NULL default '0',
label varchar(255) NOT NULL default '',
PRIMARY KEY (menuItemID),
INDEX parentMenuItemID (parentMenuItemID)
) TYPE=myISAM;
At the top level parentMenuItemID is 0, otherwise it's the value of its
parent menuItem. Then you recursively load the menu structure. I think there
are some good PEAR classes to do this.
Regards,
Torsten Roehr