troubleshooting Question

Next Previous Paging

Avatar of andrewstone2004
andrewstone2004 asked on
Web Servers
11 Comments1 Solution858 ViewsLast Modified:
Hi all,

I am currently working on a simple search page with a next previous interface and want to limit the amount of numbers in my navigation that are displayed on output. At the moment all the navigation numbers are displayed at the bottom i.e [PREVIOUS] 1 2 3 4 5 6 7 8 9 10 11 12 [NEXT] with the current page being displayed as 1 2 3 [4] 5 6 7. What I am trying to do is limit this so if there are 20 pages of 5 (<cfset RowsPerPage = 5>) being displayed - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 I want to control how many bottom numbers to display at any one time and for the next link to cycle through them - [PREVIOUS] 1 2 3 4 [5] [NEXT]........... [PREVIOUS] 10 11 12 13 [14] [NEXT] etc etc. My current code is shown below.

Thanks,

Andy


<cfquery name="Search" datasource="myDatasource">
      
SELECT Name
FROM myTable
WHERE 0=0

ORDER BY
tableColumn ASC
      
</cfquery>

<cfset RowsPerPage = 5>

<cfparam name="URL.StartRow" default="1" type="numeric">

<cfparam name="URL.ShowAll" TYPE="boolean" DEFAULT="No">

<cfset TotalRows = Search.RecordCount>

<cfset EndRow = Min(URL.StartRow + RowsPerPage - 1, TotalRows)>

<cfset StartRowNext = EndRow + 1>

<cfset StartRowBack = URL.StartRow - RowsPerPage>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<cfloop query="Search" startrow="#URL.StartRow#" endrow="#EndRow#">
<cfoutput>
#Search.Name#<br />
</cfoutput>
</cfloop>


<cfoutput>
<cfif StartRowBack GT 0>
<a href="#CGI.SCRIPT_NAME#?StartRow=#StartRowBack#">[<< BACK]</a>
</cfif>
</cfoutput>

<cfset ThisPage = 1>
<cfloop from="1" to="#TotalRows#" step="#RowsPerPage#" index="PageRow">
<cfset IsCurrentPage = (PageRow GTE URL.StartRow) AND (PageRow LTE EndRow)>
<cfif IsCurrentPage>
<cfoutput>[#ThisPage#]</cfoutput>

<cfelse>
<cfoutput>
<a href="#CGI.SCRIPT_NAME#?StartRow=#PageRow#">#ThisPage#</a>
</cfoutput>  
</cfif>

<cfset ThisPage = ThisPage + 1>
</cfloop>

<cfoutput>
<cfif StartRowNext LTE TotalRows>
<a class="s11-c6-b" href="#CGI.SCRIPT_NAME#?StartRow=#StartRowNext#">[NEXT >>]</a>
</cfif>
</cfoutput>

</body>
</html>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros