Jump to content

Vertical Menu


Pro.Luv

Recommended Posts

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

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

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.