Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Problem with sort order on paginated results page
Old 06-08-2009, 11:42 AM Problem with sort order on paginated results page
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
I have a SQL statement (then engine I'm using is MySQL) that looks like this:
Quote:
select r.*, u.name as clinic from requests r, user u where u.user_id=r.clinic order by date desc limit 15,15
This the default query for the page, and it works fine. It represents page two of a bunch of medical billing data, ordered by date desc. The problem is, the individual results pages, which display some data in a table, are supposed to be sortable, by clicking an up or down arrow at the top of each column. I do this by making an AJAX call to another page, which calls the same function which generated the results the first time, but with a different sort order. So, for example, when I click the "patient name" column, it is supposed to sort by patient last name, and the SQL statement becomes this:
Quote:
select r.*, u.name as clinic from requests r, user u where u.user_id=r.clinic order by last_name asc limit 15,15
The problem is, it now sorts ALL of the results by last_name before applying the 15,15 limit, which changes my second page results completely. Obviously this is logically what should happen with the above query, but I cannot seem to sort just the second page by last_name, or whatever, after the 15,15 limit has been applied to some other sort order.

I tried making the above SQL statements into this:
Quote:
select r.*, u.name as clinic from requests r, user u where u.user_id=r.clinic order by r.requests_id desc, date desc limit 15,15
and
Quote:
select r.*, u.name as clinic from requests r, user u where u.user_id=r.clinic order by r.requests_id desc, last_name asc limit 15,15
Where requests_id is a an auto incrementing unique, but this just seems to cause the results not to be sorted at all.

How can I sort just a 15,15 limit AFTER the whole result been sorted by some other means, so I can paginate and then sort on demand?
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
 
Register now for full access!
Old 06-08-2009, 02:27 PM Re: Problem with sort order on paginated results page
NullPointer's Avatar
Will Code for Food

Posts: 2,787
Name: Matt
Location: Irvine, CA
Trades: 0
I may not be completely understanding what you are doing, but it seems to me that you can do this with a subquery:

Code:
SELECT * FROM (
select r.*, u.name as clinic from requests r, user u where u.user_id=r.clinic order by date desc limit 15,15 
) ORDER BY last_name ASC;
This probably isn't the best solution but I think it will work.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-08-2009, 03:36 PM Re: Problem with sort order on paginated results page
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Actually, it turns out that my basic premise was not very intuitive for a user. We decided that if the user was on a sub-page, and decided to sort a column, it would return to page#1 and sort the entire record, as normal. This would allow the logical browsing of an entire sorted result, which I think is the right thing to do.

Thanks for helping, though. My SQL skills are not where they should be.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 06-08-2009 at 03:37 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Problem with sort order on paginated results page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.76210 seconds with 12 queries