Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
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?
|