how to link pages to menu dynamically in php?
I have page and menu mysql database table, how do i link pages with menu and submenus in php ? pls help. Thanks
CREATE TABLE `menu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`shortdesc` varchar(2开发者_StackOverflow社区55) NOT NULL,
`longdesc` text NOT NULL,
`status` enum('active','inactive') NOT NULL,
`parentid` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=latin1
CREATE TABLE `pages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`keywords` varchar(255) NOT NULL DEFAULT '',
`description` varchar(255) NOT NULL DEFAULT '',
`path` varchar(255) NOT NULL DEFAULT '',
`content` text NOT NULL,
`status` enum('active','inactive') NOT NULL DEFAULT 'active',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
Assuming you mean you have a menu-table that has all your menu items and you want to link them to a page, assuming that if you have a page-id you can then easily load that page.
Not all pages have a corresponding menu-item, but all menu-items have a page (where they link to).
I'd say you want to add a "pageId" field to your menu table. Indexed, not unique, maybe allowing NULL for the parent (i don't know what that is for, but that might be a header-type thing without a link?).
You're on MyISAM, so no constraints possible, that leaves adding this:
`pageId` int(11) NULL
精彩评论