Jump to content

I need help querying a database for a menu


TechMistress

Recommended Posts

Hello experts!

 

I am doing a dynamic 'popout' menu populated by items in a table. I'm almost there, but I don't know enough to do it just right.

 

I want the menu to be 3 levels deep. The table has the following fields:

parent_id, cat_id, cat_name

 

The script is from dynamic drive, and the js files are already in place. I'm just not calling the table correctly. The first item (automotive) is missing, and obviously all of my subcategories are not showing.

 

I tried 'recycling' code from a couple of my other pages, so obviously that's where I went wrong. The $i portion is probably wrong, or something.

 

Any help???

 

Here's what I have so far:

<script type="text/javascript" src="ddlevelsfiles/ddlevelsmenu.js">

<?
         $uSql = "SELECT cat_name, cat_id FROM categories WHERE parent_id ='0' ORDER by cat_name";
         $uResult = mysql_query($uSql);
          while($uRow = mysql_fetch_array($uResult)){
         $pid = $uRow["cat_id"];
         $cat_name = $uRow['cat_name'];
  ?>

<div id="ddsidemenubar" class="markermenu">
<ul>
<li><a href="/projects.php?cat="<? echo "$pid"; ?>" rel="ddsubmenuside1" id="<? echo "$i"; ?>"><? echo "$cat_name"; ?></a></li>
</ul>
</div>

<script type="text/javascript">
ddlevelsmenu.setup("ddsidemenubar", "sidebar") //ddlevelsmenu.setup("mainmenuid", "sidebar")
</script>

<!--Side Drop Down Menu 1 HTML-->
                  <? $sql2  = "SELECT cat_name, cat_id FROM categories WHERE parent_id='$pid'";
                     $result = mysql_query($sql2);
                     while($row = mysql_fetch_array($result)){
                     $cname = $row['cat_name'];
                     $cid = $row['cat_id'];
	}
                     ?>
<ul id="ddsubmenuside1" class="ddsubmenustyle blackwhite">
<li><a href="/projects.php?cat=<? echo "$cid"; ?>"><? echo "$cname"; ?></a></li>
</ul>
<?
  $i++;
  }
  ?>

 

You can see the result here:  66.70.114.97/menu/

 

Right now I have it configured for 2 levels, but there will be 3.

 

Link to comment
Share on other sites

  • 2 weeks later...
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.