Jump to content

database driven menu


dmschenk

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/62309-database-driven-menu/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.