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>
Post a comment