TechMistress Posted February 12, 2009 Share Posted February 12, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/144952-i-need-help-querying-a-database-for-a-menu/ Share on other sites More sharing options...
jamina1 Posted February 13, 2009 Share Posted February 13, 2009 So what you're trying to do is basically for each parent id, print out its name. Find each category under that parent and print out its name. And then find any sub categories with that category as their parent and print that.. correct? Quote Link to comment https://forums.phpfreaks.com/topic/144952-i-need-help-querying-a-database-for-a-menu/#findComment-761390 Share on other sites More sharing options...
TechMistress Posted February 13, 2009 Author Share Posted February 13, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/144952-i-need-help-querying-a-database-for-a-menu/#findComment-761420 Share on other sites More sharing options...
TechMistress Posted February 24, 2009 Author Share Posted February 24, 2009 You can see what I mean here: http://66.70.114.97/menu/ the first item is missing, and the rest aren't showing the sub. Quote Link to comment https://forums.phpfreaks.com/topic/144952-i-need-help-querying-a-database-for-a-menu/#findComment-770446 Share on other sites More sharing options...
fenway Posted February 25, 2009 Share Posted February 25, 2009 That's because you're not actually printing out any HTML in your PHP loops... Quote Link to comment https://forums.phpfreaks.com/topic/144952-i-need-help-querying-a-database-for-a-menu/#findComment-770823 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.