faqts : Computers : Programming : Languages : ColdFusion

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 6 people (83%) answered Yes
Recently 5 of 6 people (83%) answered Yes

Entry

How can I put page number and break my query results into groups of 20 or so?

Apr 13th, 2004 06:17
Nathan Stanford, http://www.cftipsplus.com/cftips.cfm?issueid=26


When you want to dynamically create a Page 1,2,3,...
http://www.cftipsplus.com/cftips.cfm?issueid=26
III. ColdFusion Tip: Page 1,2,3,... 
=============================================================
When you want to dynamically create a Page 1,2,3,...
=============================================================
<!--- 
First you give it the Max number of Rows 
Then the Default StartRow
Then you Add those to Plus one to get the last row.
--->
<cfset maxrows=5>
<cfparam name="url.startrow" default=1>
<cfset LastRow=#url.startrow#+#maxrows#-1>
<cfquery name="qry_test" datasource="capmatch">
select * 
from user
</cfquery>
<cfoutput query="qry_test"
startrow="#url.startrow#" maxrows="#maxrows#">
#fname# #lname#<br>
</cfoutput>
<table>
<cfif #qry_test.recordcount# gt #maxrows#> 
<tr><td colspan="4" align="center">
<cfoutput>
<cfset Next = #url.startrow#+#maxrows#>
<cfset page=1>
<cfloop index="cnt" 
from="1" to="#qry_test.recordcount#" step="#maxrows#">
<cfif #cnt# eq 1><b>Page </b>
<cfif #url.startrow# eq 1>
<b>1</b>
<cfelse>
<a href="caplist.cfm?startrow=1">1</a> 
</cfif>
<cfelse>
<cfset page=#page#+1>
<cfif #cnt# eq #url.startrow#>
<b>#page#</b>
<cfelse>
<a href="caplist.cfm?startrow=#cnt#">#page#</a>
</cfif>
</cfif>
</cfloop>
</cfoutput>
</cfif>
</table>