PDA

View Full Version : Mutiple Pages - items not in squence


Kalessin
02-14-2006, 08:30 AM
I have a bunch of internal office memos in a database, which I retrieve using:
$all_memos=mysql_query("SELECT * FROM memos WHERE (visible='yes' AND date>'$inc_date') ORDER BY date DESC");
This, obviously, returns all memos within a specified time frame and sorts them by date order.

I would like to use LIMIT to split the contents over multiple pages to speed things up, but my problem is that the memos can be edited after they've been written. This means that the date will become more recent, whilst the memo record's unique ID (primary key) will remain the same.

Thus, I need to perform a LIMIT on records which have already been sorted by date, otherwise the first page may theoretically omit the most recent memos.

Do I need to use more than one SELECT, or would it be quicker to retrieve all results, then sort them in PHP?

Thanks,

Kal

ExtraDog
02-14-2006, 10:49 AM
As I understand it the LIMIT clause is processed last and constrains the output by the (post-ORDER BY) row number not the primary key.

scoutt
02-14-2006, 02:48 PM
limit will only limit the resutls you get from this query

$all_memos=mysql_query("SELECT * FROM memos WHERE (visible='yes' AND date>'$inc_date') ORDER BY date DESC");

if the memo is listed without using limit then it will be listed after you use limit, this of course is if the memo is within the limit. it has nothgin to do with anything, date or primary_key.

Kalessin
02-15-2006, 01:50 AM
Thanks for your help guys. That explains why I couldn't find any tutorials which included the workaround I thought I needed :)

Kal