Dana,
The easiest way to cache the query is with the 'cachedwithin' attribute of
<cfquery>. For example <cfquery name="myQuery" datasource="myDataSource"
cachedwithin="#createtimespan(0,0,30,0)#"> would cache your query for 30
minutes. The only time the page will be slowed down is every 30 minutes
when the query refreshes, and the caching time can be changed easily
depending on how often your data changes.
For displaying 10 rows at a time, use the 'startrow' and 'maxrows'
attributes of <cfoutput>. <cfoutput query="myQuery" startrow="11"
maxrows="10">.
There are other ways to do this, but if this meets your needs it is most
likely the simplest.
Dan
-----Original Message-----
From: Dana Larose [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 30, 2000 8:20 AM
To: [EMAIL PROTECTED]
Subject: On storing query results in session variables
Hello everyone, I need advice on whether I've come up with a good idea, or a
horrible monstrosity :)
The scenario is this: I have a search results page (it's for a tourism
site) that can return, with the widest possible search criteria over 1000
records, but the page is designed to display the results 10 at a time.
The first idea was pretty dumb (although I prefer to call it 'Rapid
Prototyping'), which was to run the query on each page, store the results in
an array, and then print out the appropriate 10 with <cfloop>. Naturally,
this was slow (the page was sometimes taking 1 or 2 secords just for the
queries), so I came up with the idea of using the SELECT TOP x qualifier,
and increment x or decrement x by 10 as the user clicked on 'next 10' or
'prev 10', which helped alleviate the speed a little, but it was still slow
as the user clicked through the results. (And re-running the same query
over and over just felt ugly and wrong)
The other day, I tried putting the query results in a 2d array and made that
array a session variable, and that worked like a charm. The first time the
page is opened, it is still slow, but after that, the pages are much faster
now that I don't run the query and re-create the array over and over again.
My boss was pleased because the pages go nice and fast, but I've been
wondering if this is a poor solution. For instance, if multiple users
connect to the site at the same time, the session variables for the searches
could eat up gobs of memory on the server.
Is there a better way of doing this? What other problems will there be with
session variables that I haven't thought of?
(BTW - sorry for the long post!)
Dana Larose
Database Design
www.cdnwebdesign.com
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.