本文介绍了分页与Coldfusion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用一个查询在Coldfusion中分页和显示页数?

Is it possible to paginate and display number of pages in Coldfusion using only one query?

我的理解是,您可以明显地使用一个查询分页,但是您需要一个额外的查询来创建页面。这是为了计算结果总数。

My understanding is you can obviously paginate with one query, but you would need an additional query to create the pages. This is in order to calculate the total number of results.

(currentPage - 1)* resultsPerPage = MySQL中的偏移查询。这个逻辑足以创建next / prev按钮。但为了知道页面的数量,我们不需要知道使用单独的查询的结果总数,然后查询数据的查询?

(currentPage - 1) * resultsPerPage = Offset in MySQL query. This logic is sufficient to create next/prev buttons. But in order to know the number of pages, would we not need to know the total number of results using a separate query, then a query of queries for the data?

推荐答案

是的,典型的基于mysql的方法需要两个查询:一个与 select count(*)从表,第二个从表格x,y 中选择a,b,c,其中x和y根据当前页面和所需的偏移量构建。

Yes, typical mysql-based method needs two queries: one with select count(*) from table, second with select a, b, c from table limit x,y where x and y are build depending on current page and needed offset.

使用单一查询,您需要选择所有记录,这在大多数情况下效率较低。

With single query you'll need to select all records, which is less efficient approach in most cases.

这篇关于分页与Coldfusion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:41