Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a recordset

Status
Not open for further replies.

fcoomermd

Programmer
Nov 20, 2002
218
CA
This is what I want to do... I am quering a database and getting back a recordset of approx 1600 records. I want the user to be able to sort by date or author (asc, desc) when the page is first loaded. I don't want the user to have to re query the database over and over. They should be able to just sort the recordset. I am almost positive this can be done, but am unsure exactly how to do it. We are using VBScript.
 
in your sql statement add ORDER by

e.g. select * from tablename order by date Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
They can't resort the page w/o reloading the page unless you mess with some dhtml goodness. :)
 
As baddos was saying about DHTML goodness. This would be tied to javascript madness where you could store your data in a javascript array for each field, so when you perform your sort, it will sort the data in the array for your table.

You might want to try the javascript forum for more details on this. I've seen it done though. _______________________________
regards,
Brian

AOL IM: FreelanceGaines

AG00280_.gif
 
I've done it, be afraid, be very afraid. Sorting 1600 records client-side (even using an enhanced quicksort or radix sort) is going to a) be slow and b) be a real pain to get working right.
It may just be me, but every time I try to write a sorting routine I always get it wrong at least once and end up crashing something. Plus the database is optimized for sorting whereas the browser is not.

I would suggest using e refreshbefore using client-side methods.
If your going to go client-side, I would create an ordering scheme so that it only has to be done one time and then re-used each time. Basically hat I mean by this is to create a binary tree node object that can hold a value, a compare type, a compare method, and a toString method. Then create binary search trees for each searchable field that stores either the entire record or simply the key from that record in the node. This way when you need an ordered list you can simply get the values (ASC would be left to right, descending would be right to left) and you wouldn't have to go throughj a laboriuos re-order every time.
I just thought this up, so don't have any examples of what appears to be a rather complex solution. Not to count the fact that you will need to dynamically destory and creates your table rows for the display each time the user re-orders whether you use my method or an ordering algorithm.

-Tarwn ________________________________________________
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Maybe introduce paging into your scenario. I'm not sure if this is a feasible solution for your business needs, but it can reduce the time it takes to query so many records.

Also, you might want to look into using the GetRows() method of the recordset object. Heck, check out some of the FAQs on this site. They are well worth it. _______________________________
regards,
Brian

AOL IM: FreelanceGaines

AG00280_.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top