benaust Posted September 29, 2008 Share Posted September 29, 2008 Unordered List Menu MYSQL PHP -------------------------------------------------------------------------------- Hi There I am stock here and could use a hand or direction. I have a site that I like to add a multi level mysql driven menu to it, I tried adapting spry menu to mysql, but always it works out to be work different when other menu levels are added. Could someone look at the code below and or direct me to a database driven menu as such. It is a vertical menu and should have all three level retrieved from database “Mysql”. Editable by admin from back end? ******************************************* <?php require_once('Connections/Connect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $ClassOneStyle = "MenuBarVertical"; $ClassTwoStyle = "MenuBarItemSubmenu"; echo "<ul id=\"MenuBar1\" class=\"".$ClassOneStyle."\">\n"; mysql_select_db($database_HCAU_Connect, $HCAU_Connect); $query_RS_MenuL1 = "SELECT * FROM MMenuLevelOne"; $RS_MenuL1 = mysql_query($query_RS_MenuL1, $HCAU_Connect) or die(mysql_error()); while ($row_RS_MenuL1 = mysql_fetch_array($RS_MenuL1)) { $LocateNextLevel1 = $row_RS_MenuL1['MMenuL1_Label']; if ($row_RS_MenuL1['MMenuL1_URL'] == "#") {$ClassIs1 = "$ClassTwoStyle";} else{$ClassIs1 = "$ClassOneStyle";} echo "<li><a class=\"".$ClassIs1."\" href=\"".$row_RS_MenuL1['MMenuL1_URL']."\">".$row_RS_MenuL1['MMenuL1_Label']."</a>\n"; mysql_select_db($database_HCAU_Connect, $HCAU_Connect); $query_RS_MenuL2 = "SELECT * FROM MMenuLevelTwo WHERE MMenuL1_Label='$LocateNextLevel1'"; $RS_MenuL2 = mysql_query($query_RS_MenuL2, $HCAU_Connect) or die(mysql_error()); $TotalSubLinks = mysql_num_rows($RS_MenuL2); $CountSub = 0; while ($row_RS_MenuL2 = mysql_fetch_array($RS_MenuL2)) { $CountSub = $CountSub+1; $LocateNextLevel2 = $row_RS_MenuL2['MMenuL2_Label']; if ($row_RS_MenuL2['MMenuL2_URL'] == "#") {$ClassIs2 = "$ClassTwoStyle";} else{$ClassIs2 = "$ClassOneStyle";} if ($TotalSubLinks >= $CountSub ) {echo "a<ul>\n";} echo "<li><a class=\"".$ClassIs2."\" href=\"".$row_RS_MenuL2['MMenuL2_URL']."\" >".$row_RS_MenuL2['MMenuL2_Label']."</a>\n"; mysql_select_db($database_HCAU_Connect, $HCAU_Connect); $query_RS_MenuL3 = "SELECT * FROM MMenuLevelThree WHERE MMenuL2_Label='$LocateNextLevel2'"; $RS_MenuL3 = mysql_query($query_RS_MenuL3, $HCAU_Connect) or die(mysql_error()); $TotalSubSubLinks = mysql_num_rows($RS_MenuL3); $CountSubSub = 0; while ($row_RS_MenuL3 = mysql_fetch_array($RS_MenuL3)) { $CountSubSub = $CountSubSub+1; //echo $CountSubSub; //echo $TotalSubSubLinks; if ($CountSubSub == 1 ) {echo "<ul>\n";} echo "<li><a href=\"".$row_RS_MenuL3['MMenuL3_URL']."\">".$row_RS_MenuL3['MMenuL3_Label']."</a></li>\n"; if ($CountSubSub == $TotalSubSubLinks ) {echo "</ul>\n";} } echo "</li>\n"; echo "aa</ul>\n"; } echo "</li>\n"; } echo "</ul>\n"; mysql_free_result($RS_MenuL1); mysql_free_result($RS_MenuL2); mysql_free_result($RS_MenuL3); ?> *************************************************** -- ---------------------------- -- Table structure for `MMenuLevelOne` -- ---------------------------- DROP TABLE IF EXISTS `MMenuLevelOne`; CREATE TABLE `MMenuLevelOne` ( `MMenuL1_ID` int(11) NOT NULL auto_increment, `MMenuL1_Position` int(11) default NULL, `MMenuL1_Label` varchar(22) default NULL, `MMenuL1_URL` varchar(250) default NULL, PRIMARY KEY (`MMenuL1_ID`) ) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=latin1; -- ---------------------------- -- Table structure for `MMenuLevelThree` -- ---------------------------- DROP TABLE IF EXISTS `MMenuLevelThree`; CREATE TABLE `MMenuLevelThree` ( `MMenuL3_ID` int(11) NOT NULL auto_increment, `MMenuL3_Position` int(11) default NULL, `MMenuL2_Label` varchar(22) default NULL, `MMenuL3_Label` varchar(22) default NULL, `MMenuL3_URL` varchar(250) default NULL, PRIMARY KEY (`MMenuL3_ID`) ) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; -- ---------------------------- -- Table structure for `MMenuLevelTwo` -- ---------------------------- DROP TABLE IF EXISTS `MMenuLevelTwo`; CREATE TABLE `MMenuLevelTwo` ( `MMenuL2_ID` int(11) NOT NULL auto_increment, `MMenuL2_Position` int(11) default NULL, `MMenuL1_Label` varchar(22) default NULL, `MMenuL2_Label` varchar(22) default NULL, `MMenuL2_URL` varchar(250) default NULL, PRIMARY KEY (`MMenuL2_ID`) ) ENGINE=MyISAM AUTO_INCREMENT=34 DEFAULT CHARSET=latin1; -- ---------------------------- -- Records -- ---------------------------- INSERT INTO `MMenuLevelOne` VALUES ('10',NULL,'By My Self 1','bms1'); INSERT INTO `MMenuLevelOne` VALUES ('9',NULL,'3Level2-1','#'); INSERT INTO `MMenuLevelOne` VALUES ('1',NULL,'3Level1-1','#'); INSERT INTO `MMenuLevelThree` VALUES ('2',NULL,'3Level1-2','Third Level Label 1','tll1'); INSERT INTO `MMenuLevelThree` VALUES ('4',NULL,'3Level1-2','Third Level Label 2','tll2'); INSERT INTO `MMenuLevelThree` VALUES ('3',NULL,'3Level1-2','Third Level Label 3','tll3'); INSERT INTO `MMenuLevelThree` VALUES ('8',NULL,'3Level2-2','Third Level Label 11','tll1'); INSERT INTO `MMenuLevelThree` VALUES ('1',NULL,'3Level2-2','Third Level Label 22','tll2'); INSERT INTO `MMenuLevelTwo` VALUES ('1',NULL,'About Us','3Level1-2','#'); INSERT INTO `MMenuLevelTwo` VALUES ('33',NULL,'About Us','3Level2-2','#'); INSERT INTO `MMenuLevelTwo` VALUES ('32',NULL,'About Us','3Level2-3','SomeUrl'); Link to comment https://forums.phpfreaks.com/topic/126280-unordered-list-menu-mysql-php/ Share on other sites More sharing options...
trq Posted September 29, 2008 Share Posted September 29, 2008 We have tags here for good reason. Your code is unreadable (dreamweaver code is terrible enough at the best of times). Link to comment https://forums.phpfreaks.com/topic/126280-unordered-list-menu-mysql-php/#findComment-652941 Share on other sites More sharing options...
benaust Posted September 29, 2008 Author Share Posted September 29, 2008 My apologies. Would you please kindly let me know how to use the code tags? I had no knowledge of this sorry. Thanks Link to comment https://forums.phpfreaks.com/topic/126280-unordered-list-menu-mysql-php/#findComment-653382 Share on other sites More sharing options...
benaust Posted September 29, 2008 Author Share Posted September 29, 2008 I have had same issues in the past with dreamweaver rewriting or completing the codes, but this seams like it is not that, unless I can not see it. They are echoed there so I do think dreamweaver would just consider them similar to text instead of recognizing them as any programming tag or so. Link to comment https://forums.phpfreaks.com/topic/126280-unordered-list-menu-mysql-php/#findComment-653389 Share on other sites More sharing options...
DarkWater Posted September 29, 2008 Share Posted September 29, 2008 My apologies. Would you please kindly let me know how to use the code tags? I had no knowledge of this sorry. Thanks Enclose any posted code in or tags. Link to comment https://forums.phpfreaks.com/topic/126280-unordered-list-menu-mysql-php/#findComment-653391 Share on other sites More sharing options...
benaust Posted September 29, 2008 Author Share Posted September 29, 2008 You mean at start of code Bla Bla Bla Is this it? Link to comment https://forums.phpfreaks.com/topic/126280-unordered-list-menu-mysql-php/#findComment-653411 Share on other sites More sharing options...
DarkWater Posted September 29, 2008 Share Posted September 29, 2008 Yeah, basically. Please repost your code with the tags. Link to comment https://forums.phpfreaks.com/topic/126280-unordered-list-menu-mysql-php/#findComment-653414 Share on other sites More sharing options...
benaust Posted October 1, 2008 Author Share Posted October 1, 2008 How do I delete this post? Link to comment https://forums.phpfreaks.com/topic/126280-unordered-list-menu-mysql-php/#findComment-654384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.