Solved

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

Posted on 2012-03-31
4
570 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
[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
  • 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
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 …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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