I have to do pagination in my project:
below code working fine just I'm not able to figure out for (next / prev) buttons how can i handle. im using mysql database it will be great help if you give me some best practice tips & if there is any other easy way? please give me reference it will be great help
here is my code:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="application/javascript"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!---
<cfquery name="data" datasource="#application.dsn#">
select * from yourTable
</cfquery>
--->
<!--- Generate fake data --->
<cfset data = queryNew("id,name","integer,varchar")>
<cfloop index="x" from="1" to="80">
<cfset queryAddRow(data, {id:x,name:"User #x#"})>
</cfloop>
<cfparam name="URL.PageId" default="0">
<cfset RecordsPerPage = 5>
<cfset TotalPages = (data.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="data">
<cfif CurrentRow gte StartRow >
<tr>
<td>#CurrentRow#</td>
<td>#name#</td>
<td>US</td>
<td>MO</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>
<nav aria-label="...">
<ul class="pagination">
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">Previous</a>
</li>
<cfloop index="Pages" from="0" to="#TotalPages#">
<cfoutput>
<cfset DisplayPgNo = Pages+1>
<cfif URL.PageId eq pages>
<li class="page-item">
<li class="page-item active">
<a class="page-link" href="##">#DisplayPgNo#</a>
</li>
<cfelse>
<li class="page-item"><a class="page-link" href="?PageId=#Pages#">#DisplayPgNo#</a></li>
</cfif>
</cfoutput>
</cfloop>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
</nav>
Here is a full pagination solution. Though you'd probably want to put the
paginateBSfunction in a reusable application variable.