Get a Quote Today!   |   + 1 (301) 424 3903




 
  Community
 
Need Help?
Visit our Training page
Request a Quote or Consultation
SIGN UP FOR THE TERATECH NEWSLETTER
 

ColdCuts

Cut: Sorting Arrays by Date
Cut#: 148 
Cut Date: 09/13/1999 
Cutter: Michael Smith 
Topic: SQL 
Overview:

Would anybody know of a way to sort the results of a cfsearch by another field (other than by relevance). I have tried putting the results into an array, then performing a bubble sort on the array, but this is time consuming for result sets greater than 100 items. I am specifically trying to order the results by descending date order. Any ideas?

 

Cut Code:
Try making a comma delimited list of the ID's of the found records ( eg found_list
= "9,12,98,123,492,494,233") by looping over the results. Then query from database
for ID's in this list and do the sorting there:

SELECT *
FROM tablename
WHERE ID IN (#found_list#)
ORDER BY #my_sort_field#

This should work until your SQL statement is at least 16k in size - or approx 2000
hits. After that you will need to put found ID's in a temporary subtable and join
back to the main one for sorting.