Developing a Left Nav menu according to the deparment and their web links by using database

Hello
There are six departments in our office and every department contian 6 or more web links.
I am trying make a left navigation bar on my web application.
All clickable links and their names are coming from the  following table
**MainMenu**
The following code works fine but Now I have to display the department name on the left nav and then below each department name display the links belongs to the department
I have another table by the name of
**Department**
The columns of **Department** Table are DepID, DepName (DepID is a primary Key)
The columsn of Main Menu Table are  MenuID, DepID, MenuName, Link (DepID is a Foriegn Key of Departement table)
Some thing liks a Yahoo left nav bar
                 
                    Admin

<a href=order.htm>Order Form</a>
 <a href=Security.htm>Security</a>
<a href=work.htm>Work Hours</a>
                  IT

<a href=service.htm>IT Service </a>
 <a href=Events.htm>IT Events </a>
<a href=orders.htm>IT orders </a>

              HR

 <a href=forms.htm> All forms</a>
 <a href=application.htm>Work App </a>
 <a href=work.htm>New App </a>
<cfquery name=qMainMenu" datasource="rmdata">
Select *
From MainMenu
</cfquery>
<cfoutput query=qMainMenu">
<a href=#qMainMenu.Link#>#MenuName#</a>
<cfoutput>

Open in new window

sfareedAsked:
Who is Participating?
 
duncancummingConnect With a Mentor Commented:
A simpler way to do it would just be to group the output on the department name.  The following code (thanks Bob!) will print out each department name with links grouped underneath.
<!--- join mainmenu to department to get depnames --->
<cfquery name=qMainMenu datasource="rmdata">
	SELECT DepName, MenuName, Link
	FROM MainMenu, Department
	WHERE MainMenu.DepID = Department.DepID
	ORDER by DepName
</cfquery>
 
<cfoutput query="qMainMenu" group="DepName">
	#qMainMenu.DepName#
	<cfoutput>
	<!--- print each link within the department group --->
		<a href="#qMainMenu.Link#">#qMainMenu.MenuName#</a>		
	</cfoutput>
</cfoutput>

Open in new window

0
 
bchesleyConnect With a Mentor Commented:
Here is one approach.  I didn't run this code so check for typos.

Regards,

Bob
<!--- store blank depname to start --->
<cfset curDepName = "">
 
<!--- join mainmenu to department to get depnames --->
<cfquery name=qMainMenu datasource="rmdata">
Select DepName, MenuName, Link
From MainMenu, Department
Where MainMenu.DepID = Department.DepID
Order by DepName
</cfquery>
 
<!--- output query results and only print department if it does not match prior value --->
<cfoutput query="qMainMenu">
	<!--- if current record DepName != curDepName output DepName --->
    <cfif #qMainMenu.DepName# NE #curDepName#>
    	#qMainMenu.DepName#
    </cfif>
	<!--- store depname to variable --->
	<cfset curDepName = #qMainMenu.DepName#>
    <!--- print each link within the deparment group --->
	<a href=#qMainMenu.Link#>#MenuName#</a> 
</cfoutput>

Open in new window

0
 
bchesleyCommented:
Simpler is better.  Nice modification.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.