如何从查询中仅提取显示所需的记录?
我正在使用数据表 jquery 插件。
我想只提取每次查询所需显示的记录到数据库中,因为表中可能有成百上千条记录。因此,不要做这样的事情,调用表中的每条记录,并且由于分页而一次只显示一定数量的记录......
<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>
有没有办法以某种方式将 startrow 和 endrow 放在 cfquery 标记或 sql 中,每次只获取一定数量的记录?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将起始点和每“页”的记录数发送到数据库,并让它仅返回这些记录。我不知道你使用的是什么数据库,但这里有一个 MS SQL Server (2005+) 查询的示例:
这将为你提供从 1000 到 1010 的记录页。
这是 mysql 版本:
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: