Pagination with next and previous links in ColdFusion
The following code gives pagination output with 'next' and 'previous' links.
<cfparam name="FirstRow" default="1">
<cfparam name="DispRecords" default="5">
<cfquery name="GetParks" datasource="cfdocexamples" >
SELECT PARKNAME, REGION, STATE
FROM Parks
</cfquery>
<cfset EndRow=FirstRow + DispRecords>
<cfif FirstRow + DispRecords GREATER THAN GetParks.RecordCount>
<cfset EndRow=999>
<cfelse>
<cfset EndRow=DispRecords>
</cfif>
<table border="1">
<tr>
<th>NO.</th>
<th>PARKNAME</th>
<th>REGION </th>
<th>STATE</th>
</tr>
<cfoutput query="GetParks" startrow="#FirstRow#" maxrows="#EndRow#">
<tr>
<td>#CurrentRow#</td>
<td>#PARKNAME#</td>
<td>#REGION#</td>
<td>#STATE#</td>
</tr>
</cfoutput>
<cfoutput>
<br>
<table border="0" cellpadding="10">
<tr>
<cfif FirstRow NOT EQUAL 1>
<cfif FirstRow GTE DispRecords>
<cfset prev=DispRecords>
<cfset prevrecord=FirstRow - DispRecords>
<cfelse>
<cfset prev=FirstRow - 1>
<cfset prevrecord=1>
</cfif>
<td> <a href="test.cfm?FirstRow=#prevrecord#">Previous</a></td>
</cfif>
<cfif EndRow LT GetParks.RecordCount>
<cfif FirstRow + DispRecords * 2 GTE GetParks.RecordCount>
<cfset next=GetParks.RecordCount - FirstRow - DispRecords + 1>
<cfelse>
<cfset next=DispRecords>
</cfif>
<td><a href="test.cfm?FirstRow=#Evaluate("FirstRow + DispRecords")#">Next
</a> </td>
</cfif>
</table>
</cfoutput>
Also refer : ColdFusion code for pagination using numbers
Comments
Post a Comment