Solved

Dynamic Menu Using CFMenu

Posted on 2010-11-12
6
892 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function 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 …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

739 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