dmschenk Posted July 29, 2007 Share Posted July 29, 2007 I am trying to create a database driven menu but am having trouble thinking how the tables should be laid out in mysql. Currently what I have only goes to a single sublevel (l2). What I was hope to do is set it up in such a way that unlimited levels would be possible without having to manually create new tables for deeper sublevels. I'm sure this has been done before but I can't seem to locate an example of it. -- Table structure for table `l1` -- CREATE TABLE `l1` ( `L1ID` int(11) NOT NULL auto_increment, `Name` char(255) NOT NULL, `Link` varchar(255) NOT NULL, `Notes` char(255) default NULL, PRIMARY KEY USING BTREE (`L1ID`) ) -- Table structure for table `l2` -- CREATE TABLE `l2` ( `L2ID` int(11) NOT NULL auto_increment, `L1ID` int(11) default NULL, `L2Name` char(255) NOT NULL, `L2Link` char(255) default NULL, `Notes` char(255) default NULL, PRIMARY KEY USING BTREE (`L2ID`) ) first level query <? for ($i = 0; $i < $numrowsL1; $i++) { $rowL1 = mysql_fetch_array($resultL1); $L1Name = $rowL1["L1Name"]; $Link = $rowL1["Link"]; ?> second level query <? $queryL2 = "select * from L2 where L1ID=".$rowL1["L1ID"]; $resultL2 = mysql_db_query($dbname, $queryL2); $numrowsL2 = mysql_num_rows($resultL2); for ($j = 0; $j<$numrowsL2; $j++) { $rowL2 = mysql_fetch_array($resultL2); $L2Name = $rowL2["L2Name"]; $Link = $rowL2["Link"]; ?> Thanks for your help Dave Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 29, 2007 Share Posted July 29, 2007 http://webscripts.softpedia.com/script/PHP-Clases/ULCSS-multilevel-menu-11656.html might save you lots of headaches Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.