March 12th, 2008, 11:49 PM
Join Date: Mar 2008
Time spent in forums: 33 m 38 sec
Reputation Power: 0
Originally Posted by richardgroen
I am looking for a dynamic menu for my website but i cant figure out how.
I want to have a menu like this: (horizontally aligned)
1Start 2Information 3Contact
1about us 2contact form 3address
1company 2flyers 3email
The 'Start', 'Information' and 'Contact' items are the headmenu items.
The about us, contact form etc are the submenu items
I have a relational database with two tables. In one I have the headmenu items and the second one the submenu items. In the submenu table i have a ID reference to the headmenu id so these two can be linked.
<!--- variables of the get_headmenu are #headmenuname# This is the title of the headmenu --->
<cfquery name="get_headmenu" datasource="#dsn#">
<!--- the submenu name variable is #submenuname# --->
<cfquery name="get_submenu" datasource="#dsn#">
where tbl_headmenuid = #get_headmenu.id#
The two queries must be added together in order to create a dynamic menu.
Can somebody help me please?
This is more of a SQL question than one for CF, although the solution will require you to do an external and internal loop using group to get the right layout.
here is the sql.
<cfquery name="getMenu" datasource="#dsn#">
h.item AS headID
,h.itme AS head
,s.item AS Sub
,s.item AS sheadid--foreign key to headid
from tbl_headmenu h
LEFT JOIN tbl_submenu s
ON s.[headMenu]id = h.id
order by h.item,s.item
This will give you a list of header menus and their associated subs then you output like this.
<cfoutput query=getMenu group='h.item'>
<cfif sheadid eq headid>
you'll have to play with it for a bit since it's been about five years since I programmed like this but with no more information this is the easiest way to get it accomplished.