Jump to content

Help please, struggling with a menu


stuart.cole

Recommended Posts

Hi, any help would be really appreciated!

 

I am trying to dynamically create a menu with sub levels but my head is now really starting to hurt!

 

I have 2 basic tables, one for Top Level menu items, then below this would be data from the other table based upon that as the parent.

 

The structure of the menu is simple and uses CSS and Java - I have attached a small example below -

 

<ul id="menu">
<!--Headline Item--><li class="sub">Products
	<ul>
<!--Sub head Item--><li><a href="#nogo">Product 1</a></li>
		<li><a href="#nogo">Product 2</a></li>
		<li><a href="#nogo">Product 3</a></li>
	</ul>
</li>
    </ul>

 

My Issue is, that I want these to be able to populate from the database as I add new items to it - I can figure out how to do it using loads of calls to the database (1 per headline item).

 

Is there a way of using PHP and MySQL to create the top Headline item, and then based on this create the sub menu - and then rinse and repeat until all available Top Level Items are used?

 

This is as close as I have got so far ...

 

<ul id="menu">
<? $query  = "SELECT * FROM nav_parent, nav WHERE nav.parent=nav_parent.parent order by nav_parent.priority";

$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
print "<li class='sub'>".$row['parent']."<ul>";
{

echo"<li><a href='".$row['link']."'>".$row['pagename']."</a></li>";}
echo "</ul></li>";
?>

</ul>

Link to comment
https://forums.phpfreaks.com/topic/114747-help-please-struggling-with-a-menu/
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.