I am using the datatables jquery plugin.
I would like to pull just the records needed for display with each query to the database, because there will possibly be 100s of thousands of records in the table. So instead of doing something like this and calling every record in the table and only showing a certain number of them at a time, due to pagination…
<cfquery name="get_users" datasource="dsn">
select user_id, first_name, last_name
from users
</cfquery>
<cfloop query="get_users" startrow="#startrow#" endrow="#endrow#">
...
</cfloop>
Is there a way to put the startrow and endrow within the cfquery tag or within sql somehow, to only get a certain number of records each time?
You’ll want to send your starting point and number of records per “page” to the database, and have it return just those records. I don’t know what database you’re using, but here’s an example of a query for MS SQL Server (2005+):
This will give you the page of records from 1000 to 1010.
Here’s the mysql version: