Solved

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

Posted on 2012-03-31
4
559 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

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.

Question has a verified solution.

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

Suggested Solutions

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 …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

10 Experts available now in Live!

Get 1:1 Help Now