...

View Full Version : Sorting SQL results



fairwinds
10-13-2002, 03:16 AM
Looking for advice on sorting results from a mySQL query. I am considering limiting the number of records sent to the user but still don't want to go back to the server to get the same records just ordered differently. I think that JavaScript is the answer somehow (and smarter way to reduce unnecessary database activity) with a few radio buttons on my page that represent the different ways of sorting such as date, name, lowest price, etc. using the same record set. Anyone put anything like this together before that can give me a starting point or direction to follow? Any help or pointers appreciated.

Regards,
Dave

Nightfire
10-13-2002, 04:07 AM
Why not just put the limit and order in the mysql query? Makes more sense to me. I don't think Javascript can change anything like this.

fairwinds
10-13-2002, 04:31 AM
Nightfire, thanks for your reply. I guess my idea is to reduce hits to the database. If I were to have say three or four sort options that could be selected, each time a user wanted a different order for the records, it would result in a call back to the database. My thinking was possibly to take the SQL query results and put them in a JavaScript array at the same time I load the result set with default sort order and try to do the sorting on the client side as opposed to the server side. This way, there would only be one request from the database regardless of which way the user wants to look at the data. What do you think?

Regards,
Fairwinds.

beetle
10-13-2002, 05:07 AM
I've done some stuff like this for internal projects. I don't have any good cut and paste code, but Vladdy (a member here) has a cool dynamic table API...

Vladdy's Tables (http://www.vladdy.net/WebDesign/DOM_Tables.html)

If this isn't what you are after, I can probably show you some of the stuff I've done...

Enjoy!

fairwinds
10-13-2002, 07:47 PM
Thanks. I'll check this out and get back to you. Much appreciated.

Regards
Fairwinds

fairwinds
10-13-2002, 08:15 PM
Hi Beetle. This is indeed interesting and relevant however I am concerned about browser support this method at this time.

Does any of your previous work take a more conventional approach that could work more universally than a DHTML table. I code mostly in PHP. JavaScript and PHP can work quite well together. I was thinking of something like a few radio buttons at the top of my table using OnClick event with the data in JavaScript array. So pull the data out of the database, manipulate it with PHP to construct the JavaScript array and present it - something like this anyway. If you have anything that could give me a starting point, it would be very helpful. Thanks for you reply - the article is indeed a good DHMTL table resource that I have bookmarked for future reference.

Regards,
Fairwinds

beetle
10-14-2002, 04:05 PM
Ok, I suggest you do this as a first step. Get PHP to output your data into a usable JS array

Also...what are your browser concerns?

fairwinds
10-14-2002, 09:39 PM
Hi Beetle. Ok, will get this far then post when ready. I am only concerned that the solution will support a broad array of brower versions out there. The DOM standard only supports the newest versions of IE, Netscape, and Mozilla from what I understand so it is almost like using CSS a few years back. Today is Canadian Thanksgiving so have to be away for a bit but will get to it this evening and post a reply. Appreciate your help.

Regards,
Fairwinds.

beetle
10-14-2002, 09:44 PM
Well....
Originally posted by fairwinds
The DOM standard only supports the newest versions of IE, Netscape, and Mozilla from what I understand so it is almost like using CSS a few years back. I don't think that's entirely accurate. Those browsers you list compromise an overwhelming majority of users (well over 90%) out there. You may want to consider contacting Vladdy and see what he has to say about the compatbility of his script....it may be your best choice and would certainly be a timesaver...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum