Solved

Displaying parent, child, grandchild pages in a navigation menu; only one child will display

Posted on 2012-03-31
4
554 Views
Last Modified: 2012-06-27
MS SQL Server 2005
CF 9.0.1
Hi. I've been working on this for a while, and need a hint. I am trying to display parent, child, grandchild pages in a navigation menu. Here is my query:
<!--- get table columns for parent, child, grandchild records--->
<cfquery name="getPages" datasource="#APPLICATION.dataSource#">
SELECT
       p.PageID     AS PageIDLevel1
      ,p.PageTitle  AS PageTitleLevel1
      ,p.SortOrder  AS SortOrderLevel1
      ,p.ParentID   AS ParentIDLevel1
      ,p.safeURL AS safeURLLevel1
      ,c.PageID     AS PageIDLevel2
      ,c.PageTitle  AS PageTitleLevel2
      ,c.SortOrder  AS SortOrderLevel2
      ,c.parentID   AS ParentIDLevel2
      ,c.safeURL AS safeURLLevel2
      ,gc.PageID    AS PageIDLevel3
      ,gc.PageTitle AS PageTitleLevel3
      ,gc.SortOrder AS SortOrderLevel3
      ,gc.parentID  AS ParentIDLevel3
      ,gc.safeURL AS safeURLLevel3

FROM #REQUEST.contentTable# p
                  LEFT JOIN #REQUEST.contentTable#  c ON c.parentID = p.pageID
                  LEFT JOIN #REQUEST.contentTable#  gc ON gc.parentID = c.PageID
WHERE ISNULL(p.parentID, 0) = 0
ORDER BY p.SortOrder asc, c.SortOrder asc, gc.SortOrder asc
</cfquery>

Open in new window


And here is the output:
<!--- menu --->
<ul class="menu">
      
<cfoutput query="getPages" group="PageTitleLevel1">

<!--- begin level 1, list of parent pages; each parent is enclosed in a list item (li) tag --->
<cfoutput group="SortOrderLevel1">
  <li><a href="/pages/#getPages.safeURLLevel1#.cfm">#getPages.PageTitleLevel1#</a>

<!--- begin level 2, list of child pages; each child is enclosed in a list item (li) tag --->
		<cfoutput group="SortOrderLevel2">
        <cfif len(pageTitleLevel2)><!--- does a level 2, child record exist?--->
        <ul>  
        <li>
        <a href="/pages/#getPages.safeURLLevel2#.cfm">#getPages.PageTitleLevel2#</a> 

<!--- begin level 3, list of grandchild pages; each grandchild is enclosed in a list item (li) tag --->
				
				  <cfoutput group="SortOrderLevel3">
                  <cfif len(PageTitleLevel3)>  <!--- does a level 3, grandchild record exist?--->
                  <ul>  
                  <li>
                  <a href="/pages/#getPages.safeURLLevel3#.cfm">#getPages.PageTitleLevel3#</a>
                  </li>
                  </ul>
                  </cfif>
                  </cfoutput><!--- close level 3 li, ul, cfif, cfoutput ---> 
 
        </li>
        </ul>
        </cfif>
        </cfoutput><!--- close level 2 li, ul, cfif, cfoutput --->
   
  
</li></cfoutput>
<!--- close level 1 li, cfoutput --->

</cfoutput><!--- close query getPages cfoutput --->
   

</ul><!--- close menu ul --->
   
        <!--- /menu --->

Open in new window


The problem is, the output displays all of the parents; but, only the first child is displayed. There should be five child pages under the About parent page. You can see the problem here:

http://test.ebwebwork.com/

I am pretty sure that I have gotten the output correct, carefully placing all ul, li, cfif, and cfoutput tags. So I am thinking there is something going wrong in my query.

What do you think? Thanks for taking a look at this.

Eric
0
Comment
Question by:Eric Bourland
  • 3
4 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 37792022
perhaps this?


<ul class="menu">
<cfoutput query="getPages" group="PageTitleLevel1">
  <!--- begin level 1, list of parent pages; each parent is enclosed in a list item (li) tag --->
  <li><a href="/pages/#getPages.safeURLLevel1#.cfm">#getPages.PageTitleLevel1#</a>

        <!--- begin level 2, list of child pages; each child is enclosed in a list item (li) tag --->
            <cfoutput group="pageTitleLevel2">
        <cfif len(pageTitleLevel2)><!--- does a level 2, child record exist?--->
        <ul>  
        <li>
        <a href="/pages/#getPages.safeURLLevel2#.cfm">#getPages.PageTitleLevel2#</a>

                  <!--- begin level 3, list of grandchild pages; each grandchild is enclosed in a list item (li) tag --->
                          <cfoutput>
                  <cfif len(PageTitleLevel3)>  <!--- does a level 3, grandchild record exist?--->
                  <ul>  
                  <li>
                  <a href="/pages/#getPages.safeURLLevel3#.cfm">#getPages.PageTitleLevel3#</a>
                  </li>
                  </ul>
                  </cfif>
                  </cfoutput><!--- close level 3 li, ul, cfif, cfoutput --->
 
        </li>
        </ul>
        </cfif>
        </cfoutput><!--- close level 2 li, ul, cfif, cfoutput --->
</li></cfoutput>
<!--- close level 1 li, cfoutput --->
</cfoutput><!--- close query getPages cfoutput --->
</ul><!--- close menu ul --->
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 37792042
gdemaria, good to hear from you.

I see how you simplified the code. There was an extra </cfoutput> at the end that I omitted. I used your optimized code, but I am still getting only one child page in the output.

I am taking another look at the query. Eric

<ul class="menu">
<cfoutput query="getPages" group="PageTitleLevel1">
  <!--- begin level 1, list of parent pages; each parent is enclosed in a list item (li) tag --->
  <li><a href="/pages/#getPages.safeURLLevel1#.cfm">#getPages.PageTitleLevel1#</a>

        <!--- begin level 2, list of child pages; each child is enclosed in a list item (li) tag --->
            <cfoutput group="pageTitleLevel2">
        <cfif len(pageTitleLevel2)><!--- does a level 2, child record exist?--->
        <ul>  
        <li>
        <a href="/pages/#getPages.safeURLLevel2#.cfm">#getPages.PageTitleLevel2#</a> 

<!--- begin level 3, list of grandchild pages; each grandchild is enclosed in a list item (li) tag --->
                  <cfoutput>
                  <cfif len(PageTitleLevel3)>  <!--- does a level 3, grandchild record exist?--->
                  <ul>  
                  <li>
                  <a href="/pages/#getPages.safeURLLevel3#.cfm">#getPages.PageTitleLevel3#</a>
                  </li>
                  </ul>
                  </cfif>
                  </cfoutput><!--- close level 3 li, ul, cfif, cfoutput ---> 
 
        </li>
        </ul>
        </cfif>
        </cfoutput><!--- close level 2 li, ul, cfif, cfoutput --->
        
</li><!--- close level 1 li --->
</cfoutput><!--- close getPages --->
</ul><!--- close menu ul --->

Open in new window

0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 37792184
I got it:  =)

    
<ul class="menu">
<cfoutput query="getPages" group="PageTitleLevel1">
  <!--- begin level 1, list of parent pages; each parent is enclosed in a list item (li) tag --->
  <li><a href="/pages/#getPages.safeURLLevel1#.cfm">#getPages.PageTitleLevel1#</a>

        <!--- begin level 2, list of child pages; each child is enclosed in a list item (li) tag --->
            
        <cfif len(pageTitleLevel2)><!--- does a level 2, child record exist?--->
        <ul>
        <cfoutput group="pageTitleLevel2">  
        <li>
        <a href="/pages/#getPages.safeURLLevel2#.cfm">#getPages.PageTitleLevel2#</a> 

<!--- begin level 3, list of grandchild pages; each grandchild is enclosed in a list item (li) tag --->
                  
                  <cfif len(PageTitleLevel3)>  <!--- does a level 3, grandchild record exist?--->
                  <ul>
                  <cfoutput>  
                  <li>
                  <a href="/pages/#getPages.safeURLLevel3#.cfm">#getPages.PageTitleLevel3#</a>
                  </li>
                  </cfoutput>
                  </ul>
                  </cfif>
                  <!--- close level 3 li, ul, cfif, cfoutput ---> 
 
        </li>
        </cfoutput>
        </ul>
        </cfif>
        <!--- close level 2 li, ul, cfif, cfoutput --->
        
</li><!--- close level 1 li --->
</cfoutput><!--- close getPages --->
</ul><!--- close menu ul --->  

Open in new window

0
 
LVL 3

Author Closing Comment

by:Eric Bourland
ID: 37792187
Thanks as always to gdemaria. Happy Saturday evening. Hope you're well.

Eric
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

18 Experts available now in Live!

Get 1:1 Help Now