Jump to content

how to loop dynamic menus


phpdragon

Recommended Posts

I want a script that writes dynamic menus with onmouseover events in a vertical setup.

What i need is it to go thru and list all my collections first, then when it has done that create the div tag hidden menus for each one from a database

I have the mouse over function working correctly but my function for the data only returns the hidden div tag menu for the last item in the sql query, can someone help me sort this out so it loops all of the catalog queries for each collection, thank you.

 

code so far

 

<?php $sql = "SELECT collection, collectionID FROM collections ORDER BY collectionID DESC";
			$result = mysql_query($sql);
			while($result_row = mysql_fetch_array($result)) {
			$menuname=$result_row["collection"];
			$collID=$result_row["collectionID"];
			echo "<tr><td class='collmenu'><a href='#' class='anchorclass $menuname' rel='$collID' rev='lr'>$menuname</a></td></tr>";
			echo "<div id='$collID' class='anylinkcsscols'>";
			}
			$catsql = "SELECT * FROM catalog WHERE collectionID='$collID' ORDER BY catalogID DESC";
			$result = mysql_query($catsql);
			while ($catrow = mysql_fetch_array($result)) {
			$catname = $catrow["name"];
			$catid = $catrow["catalogID"];
			echo "<div class='column'><ul>";
			echo "<li><a href='products.php?catalogID=$catid&pagecount=1&collectionID=$collID'>$catname</a></li>";
			echo "</ul></div>";
			}
			echo "</div>";

 

example at http://ausglobal.buildfit.com, the menu section under product catalogs

Link to comment
https://forums.phpfreaks.com/topic/144358-how-to-loop-dynamic-menus/
Share on other sites

it only seems to loop the last variable for each and totally ignores the previous variables

here is the latest code I am playing with

 

<?php $sql = "SELECT collection, collectionID FROM collections ORDER BY collectionID DESC";
			$result = mysql_query($sql);
			while($result_row = mysql_fetch_array($result, MYSQL_ASSOC)) {
			$menuname=$result_row["collection"];
			$collID=$result_row["collectionID"];
			echo "<tr><td class='collmenu'><a href='#' class='anchorclass $menuname' rel='$collID' rev='lr'>$menuname</a></td></tr>"; 
			echo "<div id='$collID' class='anylinkcsscols'><div class='column'><ul>"; 
			$catsql = "SELECT * FROM catalog WHERE collectionID='$collID' ORDER BY catalogID DESC";
			$result = mysql_query($catsql);
			while ($catrow = mysql_fetch_array($result, MYSQL_ASSOC)) {
			$catname = $catrow["name"];
			$catid = $catrow["catalogID"];
			echo "<li><a href='products.php?catalogID=$catid&pagecount=1&collectionID=$collID'>$catname</a></li>";
			}
			echo "</ul></div>";
			echo "</div>";}
			?>

it needs to loop finished html for each collection like this to work:-

 

<tr><td class='collmenu'><a href='#' rel='$collID'></td></tr>

<div id='$collID' class='anylinkcsscols'><div class='column'><ul>

/// all catalog name variables in each collection<li><a href='link.php'></li>

</ul></div></div>

 

thats the looped result i am trying to get, actual variables listed in included code

 

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.