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.

 

Yes, basically. It will be a dhtml menu - but that's the easy part. I just don't know the exact query to get the main cat first, then any subsequent cats.

 

As I showed in my code... I got kind of close, but not correct.

  • 2 weeks later...

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.