Skip to main content
September 11, 2007
Question

Re-sort Queries

  • September 11, 2007
  • 4 replies
  • 588 views
What is the most efficient and effective way to resort a query of data after it has been displayed on the page? Can I use query of queries for this?

For example, once a recordset is displayed on a page, I'd like to give the option to sort the data by alphabetical, or when it was updated.

I tried the QoQ and it says the query is not found in memory.

Do I have to go back to the database and query to do this or is there a quicker way?
This topic has been closed for replies.

4 replies

September 11, 2007
thanks all
Inspiring
September 11, 2007
The tersest answer is: YES.


Any or all your thoughts apply depending on what you want to do and how
you want to build the user interface.

It sounds like you had some controls that made a new request to the
server and then tried to sort the data with a QofQ. This will work, but
you have to have saved the data from the original request so that you
have something to query. If you have not done something to save the
original query in a persistent scope such as session, application or
server, then it was thrown away when the first request was completed and
sent to the client.

Some of your options are re-query the database, save the original query
in a persistent scope to be used again, use DHTML or Flash client side
code that sorts the results without new requests, use Ajax that does use
a new request, but does not need to refresh the browser, ect.

As you can see there are many ways to skin this particular requirement
and which one you use depends on your ultimate goals, how comfortable
you are with any and all the technologies and techniques involved, and
any complicating factors such as paging which can significantly confuse
the issue of sorting.

September 11, 2007
Sure, thanks Eric. One thing though, that would require going back to the database to capture the recordset, can I resort this by not going to the database (ie: QoQ)?
Known Participant
September 11, 2007
you could do it that way...or just requery. QofQ is more efficient for working with a dataset. Dependingon how much data you are workign with...it may not matter.

Eric
Known Participant
September 11, 2007
Best thing to do is make your header row a series of links:

name department date
Eric IT 9/11/2007
Joe Sales 5/25/2006

So if I want to sort by name, click on "name". If i want to sort on department...click on "department"...you get the picture...

the link would look like index,cfm?sortby=name or sortby=1

in your query:

select name, department, date
from employee
order by
<cfif order_by eq "name">
name
<cfelseif order_by eq "department">
department
<cfelse>
name>
</cfif>

Eric