Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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”

  • #5
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I'll check this out and get back to you. Much appreciated.

    Regards
    Fairwinds

  • #6
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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”

  • #8
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...
    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”


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •