Posts

Showing posts from February, 2014

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>  

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&