My website pages are loading slowly and I have a feeling it's associated to the 
way I am building the menu structure for the site - through querries... My 
first guess is that I should cache the querry or cache the page - or both - but 
I can't tell if it's actually doing it or helping - so I thought I would ask 
about what I am doing and probably - how I should be doing it. (as I know the 
code is less than glorious.)

In my MySQL database - I have two tables. Content and ContentMenu. ContentMenu 
associates the content to eachother through AssocID and PageID to create the 
site hierarchy.

Example: PageID = 0 (homepage or root) In ContentMenu, any PageID associated 
(AssocID) to "0" is a main navigational page. (Products, Services, etc.)  It's 
very straight forward - but theoretically you could have a tree 5 to 10 levels 
deep.  Since I am running loops of querries - I only went 4 levels deep. (But I 
suspect it could be all be done with a Join - which I don't know how to use.)

Code as follows - - thanks again! - Nick

<!--- This code Caches the page --->
<cfcache action="clientcache" timespan="#CreateTimeSpan(0,1,0,0)#">


<cfparam name="root" default="/">


<cfquery name="qryGetAllMenu" datasource="#datasource#" username="#username#" 
password="#password#" cachedWithin="#CreateTimeSpan(0,1,0,0)#">
SELECT ContentMenu.PageID, Content.Title, ContentMenu.AssocID, ContentMenu.Sort
FROM ContentMenu, Content
WHERE ContentMenu.AssocID = '0'
AND Content.PageID = ContentMenu.PageID
AND Content.Active = 1
ORDER BY Sort ASC
</cfquery>

<cfquery name="qryGetSubPages" datasource="#datasource#" username="#username#" 
password="#password#"cachedWithin="#CreateTimeSpan(0,1,0,0)#">
SELECT ContentMenu.PageID, Content.Title, ContentMenu.AssocID, ContentMenu.Sort
FROM ContentMenu , Content
WHERE ContentMenu.AssocID <> '0'
AND Content.PageID = ContentMenu.PageID
AND Content.Active = 1
ORDER BY Sort, AssocID ASC
</cfquery>

<ul id="treemenu1" class="treeview">
        <li><a href="#root#index.cfm"><strong>Home</strong></a> </li>
                  

<!--- Get Layer 1 Menu --->
<cfloop query="qryGetAllMenu">
<cfoutput>

        <!--- Print Root Menu --->
        <li><a 
href="#root#interior_page.cfm?PageID=#PageID#"><strong>#Title#</strong></a>
        
                <!--- Check For Sub Pages --->
                <cfquery name="qryCheckPageID" dbtype="query" 
username="#username#" 
password="#password#"cachedWithin="#CreateTimeSpan(0,1,0,0)#">
                        SELECT PageID, Title, AssocID
                        FROM qryGetSubPages
                        WHERE #qryGetAllMenu.PageID# = AssocID
                        ORDER BY Sort ASC
                </cfquery>
        
                <!--- If There Are Sub Pages --->
                <cfif qryCheckPageID.recordcount EQ 0></li><cfelse>     
        
                        <ul>
                        <!--- Loop through Menu --->
                        <cfloop query="qryCheckPageID">
                                <li><a 
href="#root#interior_page.cfm?PageID=#qryCheckPageID.PageID#">#qryCheckPageID.Title#</a>
                                
                                                <!--- See if Sub Page has any 
pages associated with it --->
                                                        <cfquery 
name="qryGetAllSubs" datasource="#datasource#" username="#username#" 
password="#password#"cachedWithin="#CreateTimeSpan(0,1,0,0)#">
                                                                SELECT 
Content.PageID, Content.Title, ContentMenu.AssocID, ContentMenu.Sort
                                                                FROM 
ContentMenu, Content
                                                                WHERE 
ContentMenu.AssocID = #qryCheckPageID.PageID#
                                                                AND 
Content.Active = 1
                                                                AND 
Content.PageID = ContentMenu.PageID
                                                                ORDER BY 
ContentMenu.Sort ASC
                                                        </cfquery>
        
        
                                                                <!--- If it 
does - Begin Layer 3 --->
                                                                <cfif 
qryGetAllSubs.recordcount EQ 0></li><cfelse>
        
                                                                <ul>
                                                                <!--- Loop 
through Menu Layer 3 --->
                                                                <cfloop 
query="qryGetAllSubs">
                                                                        <li><a 
href="#root#interior_page.cfm?PageID=#qryGetAllSubs.PageID#">#qryGetAllSubs.Title#</a>
   
                                                                                
<!--- See if Page has any pages associated with it --->
                                                                                
<cfquery name="qryGetAllSubs2" datasource="#datasource#" username="#username#" 
password="#password#"cachedWithin="#CreateTimeSpan(0,1,0,0)#">
                                                                                
        SELECT Content.PageID, Content.Title, ContentMenu.AssocID, 
ContentMenu.Sort
                                                                                
        FROM ContentMenu, Content
                                                                                
        WHERE ContentMenu.AssocID = #qryGetAllSubs.PageID#
                                                                                
        AND Content.Active = 1
                                                                                
        AND Content.PageID = ContentMenu.PageID
                                                                                
        ORDER BY ContentMenu.Sort ASC
                                                                                
</cfquery>
        
                                                                                
                <!--- If it does show an arrow --->
                                                                                
                <cfif qryGetAllSubs2.recordcount EQ 0></li><cfelse>     
                                                                                
                                <ul>
                                                                                
                                        <!--- loop Layer 3 --->
                                                                                
                                        <cfloop query="qryGetAllSubs2">
                                                                                
                                                        <li><a 
href="#root#interior_page.cfm?PageID=#qryGetAllSubs2.PageID#">#qryGetAllSubs2.Title#</a></li>
                                                                                
                                        </cfloop>
                                                                                
                                </li></ul>    
                                                                                
                </cfif>
                                                                </cfloop>
                                                                </li></ul>
                                                                </cfif>

                        </cfloop>
                        </li></ul>
        </cfif>

</cfoutput>
</cfloop>



        </ul>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create Web Applications With ColdFusion MX7 & Flex 2. 
Build powerful, scalable RIAs. Free Trial
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJS 

Archive: 
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:2648
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15

Reply via email to