Richard:

There are two steps involved in doing this, data retrieval and data display.

On the retrieval side, as others have mentioned, you'd be well served
caching the results of the query.  If the query is user-specific, cache it
in SESSION.  If the query is not user-specific, you might try adding it to
ColdFusion's query cache.  If the query is not user-centric and will not
change over time, cache it in APPLICATION.

On the display side, regardless of how it's cached, you can use the STARTROW
and MAXROWS attributes of the CFOUTPUT tag to make a "prev/next n" style
display.  Your code would look something like:

        <!--- Init MAXROWS and STARTROW --->
        <CFPARAM NAME="URL.StartRow" DEFAULT="1">
        <CFPARAM NAME="URL.MaxRows" DEFAULT="10">

        <!--- Output up to MaxRows results starting from StartRow --->
        <CFOUTPUT QUERY="myQuery" MAXROWS="#URL.MaxRows#"
STARTROW="#URL.StartRow#">
                #myQuery.Col1# - #myQuery.Col2#<BR>
        </CFOUTPUT>

        <!--- Display prev/next MaxRows links --->
        <CFIF myQuery.RecordCount NEQ 0>
                <CFIF URL.StartRow GT URL.MaxRows>
                        <CFSET tmpStartRow = URL.StartRow - URL.MaxRows>
                        <A 
HREF="results.cfm?MaxRows=#URL.MaxRows#&StartRow=#tmpStartRow#">&##60;
Previous #URL.MaxRows# Results</A> |
                </CFIF>

                <CFSET EndRow = URL.StartRow + URL.MaxRows - 1>
                Results #URL.StartRow# -
                <CFIF EndRow LT myQuery.RecordCount>
                        #EndRow#
                <CFELSE>
                        #myQuery.RecordCount#
                </CFIF>

                <CFIF EndRow LT myQuery.RecordCount>
                        <CFSET tmpStartRow = URL.StartRow + URL.MaxRows>
                        <CFIF EndRow + URL.MaxRows LTE myQuery.RecordCount>
                                <CFSET nextNum = URL.MaxRows>
                        <CFELSE>
                                <CFSET nextNum = myQuery.RecordCount - EndRow>
                        </CFIF>
                        | <A 
HREF="results.cfm?MaxRows=#URL.MaxRows#&StartRow=#tmpStartRow#">Next
#nextNum# Results &##62;</A>
                </CFIF>
        </CFIF>

HTH

--
Mosh Teitelbaum
evoch, LLC
Tel: (301) 942-5378
Fax: (301) 933-3651
Email: [EMAIL PROTECTED]
WWW: http://www.evoch.com/


> -----Original Message-----
> From: admin [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 19, 2003 1:36 PM
> To: CF-Talk
> Subject: Large Recordset Display Problem
>
>
> I have a query that returns the results of a search. Potentially
> this could be a few hundred records. What I want to be able to do
> is execute the query once (as it's a slow query) but then only
> display a limited number of records per page (25 or so) and have
> some navigation to move thru the results, but with out re-doing
> the search.
>
> Any thoughts ?
>
> TIA
>
> Richard
>
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to