Pro.Luv Posted June 23, 2008 Share Posted June 23, 2008 Hi, I been trying to figure out how to do this but I have no luck in finding out how to... I have a vertical list menu... I want to load the main menu titles from the database and I want to load the sub menu from the database.. <ul> <li><a href="#">main menu</a> <ul>Sub menu</ul> </li> <li><a href="#">main menu 1</a> <ul>Sub menu</ul> </li> <li><a href="#">main menu 2</a> <ul>Sub menu</ul> </li> <li><a href="#">main menu 3</a> <ul>Sub menu</ul> </li> </ul> I tried this it works but it doesn't group them it prints the main category then the sub menu... it prints out the main category again and again and the sub menu.. like if there's 2 sub menu's that's meant to be under a certain main category say for example. Home is the main category it does this: Home Tables Home Lounge Suites It does each sub menu seperately... <? $conn = pg_connect ("host= localhost port=5432 dbname=test"); #============================================================== $sql = "SELECT DISTINCT tblproductcategory.productcategoryid,tblproductcategory.productcategory, tblproducttype.productcategoryid,tblproducttype.producttype FROM tblproductcategory"; $sql .= " INNER JOIN tblproducttype ON tblproducttype.productcategoryid = tblproductcategory.productcategoryid"; $sql .= " GROUP BY tblproductcategory.productcategoryid,tblproductcategory.productcategory, tblproducttype.productcategoryid,tblproducttype.producttype"; $sql .= " ORDER BY tblproductcategory.productcategoryid,tblproductcategory.productcategory, tblproducttype.productcategoryid,tblproducttype.producttype"; $r_query = pg_query($conn, $sql); while($arr=pg_fetch_array($r_query)) { If($arr[1] <> $arr[1]){ Print "<b>".$arr[1]."</b><br>"; } Print $arr[3]."<br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/111485-vertical-menu/ Share on other sites More sharing options...
dmccabe Posted June 23, 2008 Share Posted June 23, 2008 Think you need a while loop within the while loop if you get what I mean. so while loop one would grab the category, then the second while loop would grab and print out the sub categories. If that makes sense while (this) print categories while (this) print subcategories Link to comment https://forums.phpfreaks.com/topic/111485-vertical-menu/#findComment-572174 Share on other sites More sharing options...
Pro.Luv Posted June 23, 2008 Author Share Posted June 23, 2008 Any help is highly appreciated, I hope it's not too much to ask but could you give me an example please. I been knocking my head around this. Thanks Link to comment https://forums.phpfreaks.com/topic/111485-vertical-menu/#findComment-572183 Share on other sites More sharing options...
blueman378 Posted June 24, 2008 Share Posted June 24, 2008 try <ul> <li class="main"><a href="#">main menu 1</a></li> <li class="sub">Sub menu</li> <li class="main"><a href="#">main menu 2/a></li> <li class="sub">Sub menu</li> <li class="main"><a href="#">main menu 3/a></li> <li class="sub">Sub menu</li> </ul> Link to comment https://forums.phpfreaks.com/topic/111485-vertical-menu/#findComment-572760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.