Solved

Dynamic Menu Using CFMenu

Posted on 2010-11-12
6
886 Views
Last Modified: 2012-05-10
Below is an example of my database structure:
| menuId | menuName | menuUrl | parentId |
| 1 | ParentPage | /ParentPage | 0 |
| 2 | ChildPage | /ParentPage/ChildPage | 1 |
| 3 | ChildChildPage | /ParentPage/ChildPage/ChildChildPage | 2 |

I can write code to output the first level of parents and children in a dropdown menu but I can't get the next 14 levels of child menu items.

I have a feeling there is an easy solution for this. I'm just not seeing it.

Any ideas?
<cfoutput>

<cfquery datasource="dbmain" name="qParent">
SELECT * FROM test_menu 
WHERE parentId = 0
</cfquery>

<cfset parentcount = 0>
<cfset childcount = 0>

<cfmenu name="menu" type="horizontal" fontsize="14" bgcolor="##CCFFFF">

	<cfloop query="qParent">
    
    <cfmenuitem name="#REPLACE(REPLACE(qParent.menuName," ","","ALL"),",","","ALL")##parentcount#"
    href="#qParent.menuUrl#" display="#qParent.menuName#"> 
    
    <cfquery datasource="dbmain" name="qChildren">
    SELECT * FROM test_menu 
    WHERE parentId = #qParent.menuId#
    </cfquery>
    
      <cfloop query="qChildren">
           <cfmenuitem name="#REPLACE(REPLACE(qChildren.menuName," ","","ALL"),",","","ALL")##childcount#1"
            href="#qChildren.menuUrl#" display="#qChildren.menuName#"/>  
            <cfset childcount++>
       </cfloop>
       
    </cfmenuitem>
    
    <cfset parentcount++>
    
    </cfloop>
    
</cfmenu>

</cfoutput>

Open in new window

0
Comment
Question by:timbad2021
  • 4
  • 2
6 Comments
 
LVL 1

Author Comment

by:timbad2021
ID: 34124053
Is everyone asleep today?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34125255
Friday-itus.

>> get the next 14 levels

14 nested levels? Then you're asking about a db query not CF. For MS SQL 2005, the answer
probably involves CTE's.  If you ask in the MS SQL 2005 zone, I'm someone there
could answer it.  (Sorry my brain's too fried to formulate a solution.)
0
 
LVL 1

Author Comment

by:timbad2021
ID: 34136716
Ok, no luck in the MS SQL zone.

How do I do this using the current database structure that I showed an example of in my first post?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Accepted Solution

by:
timbad2021 earned 0 total points
ID: 34137512
Found the answer:
http://dbtree.megalingo.com/
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34138102
Sorry I didn't see your follow up comments.  Glad you found a solution :)

>> Ok, no luck in the MS SQL zone.

With all due respect, the question was lacking in the details department ;-) The more info you give the experts, the better response you'll get.  Next time be sure post your table structure, and sample of the desired results.  It'll help you get a better (and faster) answer next time.

Menu Level 1
---Menu level 1.1
-----Menu level 1.1.1
--------Menu level 1.1.1.1

0
 
LVL 1

Author Closing Comment

by:timbad2021
ID: 34179024
Yep.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question