Solved

Dynamic Menu Using CFMenu

Posted on 2010-11-12
6
883 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
3 Use Cases for Connected Systems

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

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now