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

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
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
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

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

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


 <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
<cfoutput query=qMainMenu">
<a href=#qMainMenu.Link#>#MenuName#</a>

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here is one approach.  I didn't run this code so check for typos.


<!--- 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
<!--- 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#>
	<!--- store depname to variable --->
	<cfset curDepName = #qMainMenu.DepName#>
    <!--- print each link within the deparment group --->
	<a href=#qMainMenu.Link#>#MenuName#</a> 

Open in new window

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
<cfoutput query="qMainMenu" group="DepName">
	<!--- print each link within the department group --->
		<a href="#qMainMenu.Link#">#qMainMenu.MenuName#</a>		

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simpler is better.  Nice modification.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.