I have a question regarding the use of LIMIT with ORDER BY.  My problem is
as follows:

I want my users to be able to pageanate through result sets, so I've written
some code
that will display the results of a query 15 rows at a time in a HTML table.
The next set of results
can be accessed by pressing the next button and ditto for the previous set.
The query is

SELECT name FROM documents LIMIT 10, 15

I want to further extend this functionality by allowing the users to click
on the column
name (in the table header) and then sort the current  set of results from by
the chosen
column.  So lets say I had the following

mysql> SELECT name FROM documents LIMIT 2, 4;

+-------------------------------------------+
| name                                      |
+-------------------------------------------+
| Visual Patterns Intellectual Property.doc |
| footer.jpg                                |
| getHWSerialNumber.txt                     |
| env.php.txt                               |
+-------------------------------------------+

Now, I want to order by name.  So I should get

+-------------------------------------------+
| name                                      |
+-------------------------------------------+
| env.php.txt                               |
| footer.jpg                                |
| getHWSerialNumber.txt                     |
| Visual Patterns Intellectual Property.doc |
+-------------------------------------------+

But, when I apply the following query

mysql> SELECT name FROM documents ORDER BY name ASC LIMIT 2, 4;

I get

+-----------------------+
| name                  |
+-----------------------+
| env.php.txt           |
| footer.jpg            |
| getHWSerialNumber.txt |
| Ideas.doc             |
+-----------------------+

I can only assume that MySql is ordering by name before limiting the result
set.  Obviously
I want the reverse.  Any ideas?

Thanks

---
Rob

**************************
Rob Cherry
mailto:[EMAIL PROTECTED]
+27 21 447 7440
Jam Warehouse RSA
Smart Business Innovation
http://www.jamwarehouse.com
**************************



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to