Hi phphelp.com!
I want to make a dymanic php hover drop-down menu as the subject says, but for some reason i can’t make it to display the sub menus, only this annoying error message.
I want to define a variable so I can use it in my to pull the sub-menus from the database, but the php code might probably explain it better for some of you.
What i want to know is why it doesn’t work for me and if I am making this way too complicated/stupid.
[php]
//Start non-loop menu part
echo ‘
- ’;
//Print menu
$query = "SELECT * FROM menu ORDER BY menu_id";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
//Main menu
if ($row['menu_level'] == '1') {
echo '<li>';
echo '<a href="index.php?case='.$row['menu_href'].'" class="text_menu" >';
echo '<div class="menu_post">'.$row['menu_name'].'</div></a>';
//Insert sub-menus here
$main_menu_id = $row['menu_id'];
echo $main_menu_id;
$query = "SELECT * FROM menu WHERE menu_level > 1 ORDER BY menu_id";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
echo '<ul>';
if ($row['menu_sub'] == $main_menu_id) {
echo '<li><a href="'.$row['menu_href'].'">'.$row['menu_name'].'</a></li>';
}
else {
//Print Error
echo 'Error!';
}
echo '</ul>';
}
//end of sub menu
//End menu
echo '</li>';
}
else {
}
}
//End non-loop menu part
echo '</ul>';
[/php]
I will also include the database table for the menu, so you get the whole picture of it:
CREATE TABLE `menu` (
`menu_id` int(11) NOT NULL auto_increment,
`menu_level` int(11) NOT NULL default '2',
`menu_sub` int(11) NOT NULL,
`menu_href` varchar(20) character set utf8 collate utf8_danish_ci NOT NULL,
`menu_name` varchar(20) character set utf8 collate utf8_danish_ci NOT NULL,
PRIMARY KEY (`menu_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
--
-- Dumping data for table `menu`
--
INSERT INTO `menu` VALUES (1, 1, 0, 'homeport', 'Homeport');
INSERT INTO `menu` VALUES (2, 1, 0, 'tarvern', 'Tarvern');
INSERT INTO `menu` VALUES (3, 1, 0, 'something', 'Something');
INSERT INTO `menu` VALUES (4, 1, 0, 'crew', 'Crew');
INSERT INTO `menu` VALUES (5, 1, 0, something', 'Something');
INSERT INTO `menu` VALUES (6, 1, 0, 'squark', 'Squark');
INSERT INTO `menu` VALUES (7, 2, 2, 'news', 'News');
INSERT INTO `menu` VALUES (8, 2, 2, 'articles', 'Articles');
INSERT INTO `menu` VALUES (9, 2, 2, 'reviews', 'Reviews');
Hope this is enough information for you to help me.