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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.