Solved

Dynamic Menu Using CFMenu

Posted on 2010-11-12
6
890 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …

735 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