But in looking at everyoneโs examples.. I now have an understanding in how this has to work (least without the stored procedure) I will also discuss this stored procedure with our DB Guru...
BUT... This is what I have and understand...
THIS WORKS!!!!
SELECT TOP 10 * FROM main
WHERE published = 1 and id NOT IN ( SELECT TOP 0 id
FROM main ORDER BY id ASC )
ORDER BY id ASC
Explanation:
SELECT TOP 10 * FROM main
The first part of this script will specify how many records to return This will always remain the same (course you can offer to the user how many records per page he wants with this.. Just substitute the "10" with a $var.
and id NOT IN ( SELECT TOP 0 id
This means its making sure that the records fetched in the first select are NOT selected in the second select. so .. with specifying '0' or zero.. this could be your first page. The '0' or zero would have to be replaced with a $var to specify how many records you want to skip.
So.. if I change the '0' to 10 for example.. Then the query would look like this..
SELECT TOP 10 * FROM main
WHERE published = 1 and id NOT IN ( SELECT TOP 10 id
FROM main ORDER BY id ASC )
ORDER BY id ASC
This means select the first 10 records that are NOT in the first 10 records so it would then select the next 10 records. If I change it to 20 then it would then skip the first 20 records and so on...
IE:
SELECT TOP 10 * FROM main
WHERE published = 1 and id NOT IN ( SELECT TOP 20 id
FROM main ORDER BY id ASC )
ORDER BY id ASC
of course the sorting need to be identical.
Example with $var:
$records_per_page = 10; //can use $GET from URL
$next_page = $next_id; //can use $GET from URL
SELECT TOP $records_per_page * FROM main
WHERE published = 1 and id NOT IN ( SELECT TOP $next_page id
FROM main ORDER BY id ASC )
ORDER BY id ASC
Does this help anyone?
I may build a function for this...