Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-13-2002, 03:16 AM   PM User | #1
fairwinds
New to the CF scene

 
Join Date: Sep 2002
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
fairwinds is an unknown quantity at this point
Question Sorting SQL results

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
fairwinds is offline   Reply With Quote
Old 10-13-2002, 04:07 AM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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.
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 10-13-2002, 04:31 AM   PM User | #3
fairwinds
New to the CF scene

 
Join Date: Sep 2002
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
fairwinds is an unknown quantity at this point
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.
fairwinds is offline   Reply With Quote
Old 10-13-2002, 05:07 AM   PM User | #4
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
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

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

Enjoy!
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 10-13-2002, 07:47 PM   PM User | #5
fairwinds
New to the CF scene

 
Join Date: Sep 2002
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
fairwinds is an unknown quantity at this point
Thanks. I'll check this out and get back to you. Much appreciated.

Regards
Fairwinds
fairwinds is offline   Reply With Quote
Old 10-13-2002, 08:15 PM   PM User | #6
fairwinds
New to the CF scene

 
Join Date: Sep 2002
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
fairwinds is an unknown quantity at this point
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
fairwinds is offline   Reply With Quote
Old 10-14-2002, 04:05 PM   PM User | #7
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
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?
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 10-14-2002, 09:39 PM   PM User | #8
fairwinds
New to the CF scene

 
Join Date: Sep 2002
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
fairwinds is an unknown quantity at this point
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.
fairwinds is offline   Reply With Quote
Old 10-14-2002, 09:44 PM   PM User | #9
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
Well....
Quote:
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...
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:15 PM.


Advertisement
Log in to turn off these ads.