[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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

0
sfareed
Asked:
sfareed
  • 2
2 Solutions
 
bchesleyCommented:
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
 
duncancummingCommented:
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
 
bchesleyCommented:
Simpler is better.  Nice modification.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now