One More Blog

Welcome to the Blog of Eric Moritz; wannabe philathropist, geek and over-all swell guy

Page Numbers for queries in Cold Fusion

For a long time, I've been recreating the wheel with this kind of functionality. I finally created a small library to handle page numbering in Coldfusion.

Download


This is how you use it:

Parameters

query
This is the query the is going to be paged
index
This is the column that the query uses to break the pages.
maxrows
This is the total number of rows on a page
current_page
This is the current page



Returned Value


The function returns the following struct:


count
The number of pages
current
The current page

current_index
The current index. This is used by your filtering query
indexes
The is an array of each page's index. Although your view template does not need to know what each page's index value you is, it is provided in case you need it.
items
The total number of items in the original query
maxrows
The total number of rows. This is the same as the parameter that you used in the function call. It is returned in the struct for convienence and encapulation.



Example


Here is an example of it's use.


<cfquery name="original_query">
select * from products order by id
</cfquery>

<cfset pages = paging(original_query,"id", 10, 1)>

<cfquery name="paged_query" maxrows="#pages.maxrows#" dbtype="query">
select * from original_query where id >= <cfqueryparam value="#pages.current_index#">
</cfquery>

<div class="page-numbers">

<cfoutput>
<cfloop from="1" to="#arraylen(pages.indexes)#" index="page">
<cfif page neq pages.current>
<a href="#get_page_url(page)#">#page#</a>

<cfelse>
#page#
</cfif>
</cfloop>
</cfoutput>
</div>

Ne esperanta versio.

Posted by on July 15, 2005

0 Comments

Tags: coldfusion

Comments

No comments found

Post a comment


Password: (Forgotten your password?)


Who are you? Log In | Sign up