Link to home
Start Free TrialLog in
Avatar of Eric Bourland
Eric BourlandFlag for United States of America

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eric Bourland

ASKER

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

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

Thanks as always to gdemaria. Happy Saturday evening. Hope you're well.

Eric