phpbeginner Posted January 3, 2013 Share Posted January 3, 2013 I have been trying to build a drop down menu with php and data from MySQL database but cannot seem to get it to work. I have the horizontal (main categories) displaying but the drop downs are not working. Appreciate any help and thanks in advance. <ul id="menu"> <?php $clsnm="active"; if (isset($_GET["id"])) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'events.php')) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'gallery.php')) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'news.php')) $clsnm="footerlink"; ?> <li class="<?php echo $clsnm;?>"><a href="index.php">Home</a></li> <li class="seplie"></li> <?php $sql = "SELECT id,title,links FROM tblmain where id > 1 and head='Yes' order by sorder asc"; $reccount=$sq->numsrow($sql); if ($reccount > 0) { $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { $clsnm="footerlink"; $phppgname=$rs["links"]; if ((isset($_GET["id"])) && ($_GET["id"]==$rs["id"])) $clsnm="active"; if ($phppgname!="") { if (strstr($_SERVER['SCRIPT_NAME'],$phppgname)) $clsnm="active"; } if ($rs["links"]=="") $phppgname="contents.php?id=".$rs["id"]; ?> <li class="<?php echo $clsnm;?>"><a href="<?php echo $phppgname;?>"><?php echo $rs["title"];?></a> </li> <li class="seplie"></li> <?php $pn++; } } ?> <?php $pnds=1; if (isset($_GET["id"])) $pnds=$_GET["id"]; $sql = "SELECT id,title,subpageid FROM tblsubpage where subpageid=".$pnds." order by id desc "; $reccount=$sq->numsrow($sql); if ($reccount > 0) { $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { ?> <ul><li><a href="subcontents.php?id=<?php echo $rs["subpageid"];?>&sid=<?php echo $rs["id"];?>"><?php echo $rs["title"];?></a></li> <?php } } ?></ul> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/ Share on other sites More sharing options...
jazzman1 Posted January 3, 2013 Share Posted January 3, 2013 Do you get any errors, and if so what errors do you get? Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/#findComment-1403050 Share on other sites More sharing options...
phpbeginner Posted January 3, 2013 Author Share Posted January 3, 2013 no errors.......just blank. If I add the sub navigation (which is what I am trying to use in the dropdown) to the left hand column, it displays fine. <?php $pnds=1; if (isset($_GET["id"])) $pnds=$_GET["id"]; $sql = "SELECT id,title,subpageid FROM tblsubpage where subpageid=".$pnds." order by id desc "; $reccount=$sq->numsrow($sql); if ($reccount > 0) { $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { ?> <ul><li><a href="subcontents.php?id=<?php echo $rs["subpageid"];?>&sid=<?php echo $rs["id"];?>"><?php echo $rs["title"];?></a></li> <?php } } ?></ul> Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/#findComment-1403059 Share on other sites More sharing options...
Barand Posted January 3, 2013 Share Posted January 3, 2013 The <ul> tag should be before the while loop.  If, as you keep mentioning, you want a dropdown menu then you should be using  <select> <option>..</option> <option>..</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/#findComment-1403066 Share on other sites More sharing options...
phpbeginner Posted January 3, 2013 Author Share Posted January 3, 2013 It's a navigation menu. Right now I have this and it works until it gets to first drop down menu....... (ie: shows Home, About Us, Services) under services it drops down as it should to show sub-categories. Then it stops and does not display any more Main Menu items after Services. <ul id="menu"> <?php $clsnm="active"; if (isset($_GET["id"])) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'events.php')) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'gallery.php')) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'news.php')) $clsnm="footerlink"; ?> <li class="<?php echo $clsnm;?>"><a href="index.php">Home</a></li> <li class="seplie"></li> <?php $sql = "SELECT id,title,links FROM tblmain where id > 1 and head='Yes' order by sorder asc"; $reccount=$sq->numsrow($sql); if ($reccount > 0) { $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { $clsnm="footerlink"; $phppgname=$rs["links"]; if ((isset($_GET["id"])) && ($_GET["id"]==$rs["id"])) $clsnm="active"; if ($phppgname!="") { if (strstr($_SERVER['SCRIPT_NAME'],$phppgname)) $clsnm="active"; } if ($rs["links"]=="") $phppgname="contents.php?id=".$rs["id"]; ?> <li class="<?php echo $clsnm;?>"><a href="<?php echo $phppgname;?>"><?php echo $rs["title"];?></a> <?php $pnds=1; if (isset($_GET["id"])) $pnds=$_GET["id"]; $sql = "SELECT id,title,subpageid FROM tblsubpage where subpageid=".$rs["id"]." order by id desc "; $reccount=$sq->numsrow($sql); if ($reccount > 0){ echo("<ul>"); ?> <?php $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { ?> <li><a href="subcontents.php?id=<?php echo $rs["subpageid"];?>&sid=<?php echo $rs["id"];?>"><?php echo $rs["title"];?></a></li> <?php } echo("</ul>"); } ?> <li class="seplie"></li> <?php $pn++; } } ?> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/#findComment-1403069 Share on other sites More sharing options...
White_Lily Posted January 4, 2013 Share Posted January 4, 2013 (edited) Barand, by drop down menu he means when you hover ( or click on some sites o.O ) then a sub menu appears. Like on Facebook when you click the settings button at the top of your profile, it then displays a drop down menu with more settings to view, personally however I have always found drop down menus a problem. Â Try this google search and you might find what you are looking for: Â http://www.google.co...iw=1280&bih=933 Â Note: Most drop down menus are not supported by some browsers (namely: IE) so it might be worth looking into something that is supported by all browsers. The google link is for pure css menus, if you something with a bit os style to it, you might find jQuery menus better, again though, these are not supported in all browsers. Edited January 4, 2013 by White_Lily Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/#findComment-1403151 Share on other sites More sharing options...
phpbeginner Posted January 4, 2013 Author Share Posted January 4, 2013 (edited) White_Lily, the issue is not creating the drop down. I have tested this one (jQuery) and it works fine in all browsers using standard coding techniques. I am having trouble with the PHP/MySQL coding I am using. I can create a standard horizontal menu and even get it working til the first drop down menu, once it gets to the first drop down menu and it actually works, it stops display the other main menu items beyond that in the horizontal display. As an example, in my test menu I have Home, About Us, Services, and Contact. I have 2 drop down items on services and once it gets there, then Contact menu item does not display. I am doing something wrong in my code below. ///Where main menu starts/// <ul id="menu"> <?php $clsnm="active"; if (isset($_GET["id"])) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'events.php')) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'gallery.php')) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'news.php')) $clsnm="footerlink"; ?> <li class="<?php echo $clsnm;?>"><a href="index.php">Home</a></li> <li class="seplie"></li> <?php $sql = "SELECT id,title,links FROM tblmain where id > 1 and head='Yes' order by sorder asc"; $reccount=$sq->numsrow($sql); if ($reccount > 0) { $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { $clsnm="footerlink"; $phppgname=$rs["links"]; if ((isset($_GET["id"])) && ($_GET["id"]==$rs["id"])) $clsnm="active"; if ($phppgname!="") { if (strstr($_SERVER['SCRIPT_NAME'],$phppgname)) $clsnm="active"; } if ($rs["links"]=="") $phppgname="contents.php?id=".$rs["id"]; ?> /// Main menu items/// <li class='<?php echo $clsnm;?>'><a href='<?php echo $phppgname;?>'><?php echo $rs['title'];?></a> ///Sub Menu Items Start///<? php $pnds=1; if (isset($_GET["id"])) $pnds=$_GET["id"]; $sql = "SELECT id,title,subpageid FROM tblsubpage where subpageid=".$rs["id"]." order by id desc "; $reccount=$sq->numsrow($sql); if ($reccount > 0){ echo("<ul>"); $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { ?> ///Sub Menu Items Display/// <li><a href="subcontents.php?id=<?php echo $rs["subpageid"];?>&sid=<?php echo $rs["id"];?>"><?php echo $rs["title"];?></a></li> <?php } echo("</ul>"); } echo("<li class='seplie'></li>"); ///Sub Menu Ends/// $ pn++; } } ?> ///Main Menu Ends </ul> Edited January 4, 2013 by phpbeginner Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/#findComment-1403181 Share on other sites More sharing options...
jazzman1 Posted January 4, 2013 Share Posted January 4, 2013 I've got a Syntax error: unexpected: $pnds! Â Did you see that on the line # 27? Â ///Sub Menu Items Start///<? php Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/#findComment-1403198 Share on other sites More sharing options...
phpbeginner Posted January 4, 2013 Author Share Posted January 4, 2013 Corrected issue, same problem............ <ul id="menu"> <?php $clsnm="active"; if (isset($_GET["id"])) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'events.php')) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'gallery.php')) $clsnm="footerlink"; if (strstr($_SERVER['SCRIPT_NAME'],'news.php')) $clsnm="footerlink"; ?> <li class="<?php echo $clsnm;?>"><a href="index.php">Home</a></li> <li class="seplie"></li> <?php $sql = "SELECT id,title,links FROM tblmain where id > 1 and head='Yes' order by sorder asc"; $reccount=$sq->numsrow($sql); if ($reccount > 0) { $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { $clsnm="footerlink"; $phppgname=$rs["links"]; if ((isset($_GET["id"])) && ($_GET["id"]==$rs["id"])) $clsnm="active"; if ($phppgname!="") { if (strstr($_SERVER['SCRIPT_NAME'],$phppgname)) $clsnm="active"; } if ($rs["links"]=="") $phppgname="contents.php?id=".$rs["id"]; ?> <li class='<?php echo $clsnm;?>'><a href='<?php echo $phppgname;?>'><?php echo $rs['title'];?></a> <?php if (isset($_GET["id"])); $sql = "SELECT id,title,subpageid FROM tblsubpage where subpageid=".$rs["id"]." order by id desc "; $reccount=$sq->numsrow($sql); if ($reccount > 0){ echo("<ul>"); $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { ?> <li><a href="subcontents.php?id=<?php echo $rs["subpageid"];?>&sid=<?php echo $rs["id"];?>"><?php echo $rs["title"];?></a></li> <?php } echo("</ul>"); } echo("<li class='seplie'></li>"); $pn++; } } ?> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/#findComment-1403203 Share on other sites More sharing options...
phpbeginner Posted January 4, 2013 Author Share Posted January 4, 2013 anyone know what I can do with the code to get the remainder of navigation items to display after the first drop down? Something in my code is hitting the first sub-navigation menu item, then not getting the remainder of the main menu items.......script ends after first Main Menu item with a drop down. Quote Link to comment https://forums.phpfreaks.com/topic/272658-dynamic-dropdown-menu/#findComment-1403247 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.