ColdFusion code for pagination using numbers
We can do pagination of results in many ways. Here the following code gives the pagination output using numbers with ColdFusion.
<cfparam name="URL.PageId" default="0">
<cfset RecordsPerPage = 5>
<cfquery name="GetParks" datasource="cfdocexamples" >
SELECT PARKNAME, REGION, STATE
FROM Parks
</cfquery>
<cfset TotalPages = (GetParks.Recordcount/RecordsPerPage)-1>
<cfset StartRow = (URL.PageId*RecordsPerPage)+1>
<cfset EndRow = StartRow+RecordsPerPage-1>
<cfoutput>
<table border="1">
<tr>
<th>No.</th>
<th>PARKNAME</th>
<th>REGION </th>
<th>STATE</th>
</tr>
<cfloop query="GetParks">
<cfif CurrentRow gte StartRow >
<tr>
<td>#CurrentRow#</td>
<td>#PARKNAME#</td>
<td>#REGION#</td>
<td>#STATE#</td>
</tr>
</cfif>
<cfif CurrentRow eq EndRow>
<cfbreak>
</cfif>
</cfloop>
</cfoutput>
<tr>
<td colspan="4">
<cfloop index="Pages" from="0" to="#TotalPages#">
<cfoutput>
<cfset DisplayPgNo = Pages+1>
<cfif URL.PageId eq pages>
<strong>#DisplayPgNo#</strong>
<cfelse>
<a href="?PageId=#Pages#">#DisplayPgNo#</a>
</cfif>
</cfoutput>
</cfloop>
</td>
</tr>
</table>
Also refer : Pagination with next and previous links in ColdFusion
<cfparam name="URL.PageId" default="0">
<cfset RecordsPerPage = 5>
<cfquery name="GetParks" datasource="cfdocexamples" >
SELECT PARKNAME, REGION, STATE
FROM Parks
</cfquery>
<cfset TotalPages = (GetParks.Recordcount/RecordsPerPage)-1>
<cfset StartRow = (URL.PageId*RecordsPerPage)+1>
<cfset EndRow = StartRow+RecordsPerPage-1>
<cfoutput>
<table border="1">
<tr>
<th>No.</th>
<th>PARKNAME</th>
<th>REGION </th>
<th>STATE</th>
</tr>
<cfloop query="GetParks">
<cfif CurrentRow gte StartRow >
<tr>
<td>#CurrentRow#</td>
<td>#PARKNAME#</td>
<td>#REGION#</td>
<td>#STATE#</td>
</tr>
</cfif>
<cfif CurrentRow eq EndRow>
<cfbreak>
</cfif>
</cfloop>
</cfoutput>
<tr>
<td colspan="4">
<cfloop index="Pages" from="0" to="#TotalPages#">
<cfoutput>
<cfset DisplayPgNo = Pages+1>
<cfif URL.PageId eq pages>
<strong>#DisplayPgNo#</strong>
<cfelse>
<a href="?PageId=#Pages#">#DisplayPgNo#</a>
</cfif>
</cfoutput>
</cfloop>
</td>
</tr>
</table>
Also refer : Pagination with next and previous links in ColdFusion
Comments
Post a Comment