Link to home
Start Free TrialLog in
Avatar of Mike Waller
Mike WallerFlag for United States of America

asked on

dynamic pages plus next/previous links

Ok, I have the following script that creates navigational pages number dynamically but I also need a Next >  and < Previous links so let's say you're on page 3 you could click on 4 to get to that page OR click Next > and that would get you there.  Same idea for the < Previous.  Let me know if you have any thoughts.  Here's what I have for the page numbers:


<!----------------------------------------------------------
START FIRST PAGE
------------------------------------------------------------>
<html>
<head>
     <title>page 1</title>
</head>

<body>

<cfquery datasource="dsn_name" name="GetImages">
Select *
FROM pickuparea
</cfquery>

<!--- What row to start at? Assume first by default --->
<cfparam name="url.startrow" default="1">
<!--- We know the total number of rows from the query --->
<cfset totalrows = GetImages.recordcount>
<!--- Allow for show all parameter in the URL --->
<cfparam name="url.showall" type="boolean" default="no">
<!--- Number of rows to display per Next/Back page --->
<cfset rowsperpage = 15>
<!--- Show all on page if show all passed in url --->
<cfif url.showall>
     <cfset rowsperpage = totalrows>
</cfif>
<!--- URL tampering --->
<cfif IsDefined("url.startrow")>
     <cfif NOT IsNumeric(url.startrow)>
          <cfset url.startrow = 1>
     </cfif>
</cfif>
<!--- Last row is 10 rows past the starting row, or total number of query rows, whichever is less --->
<cfset endrow = min(url.startrow + rowsperpage - 1, totalrows)>
<!--- Next button goes to 1 past current end row --->
<cfset startrownext = endrow + 1>
<!--- Back button goes back N rows from start row --->
<cfset startrowback = url.startrow - rowsperpage>


     
        <table width="100%" border="0" cellpadding="2" cellspacing="0" >
          <tr>
            <td><strong>item pic numbers:</strong></td>
          </tr>
          <cfloop query="GetImages" startrow="#url.startrow#" endrow="#endrow#">
            <cfoutput>
              <tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('F9F8F8'))#">
                <td>#GetImages.id#</td>
              </tr>
            </cfoutput>
          </cfloop>
        </table>
                   
        <cfif not url.showall and totalrows GT rowsperpage>
          <!--- Shortcut links for page of search results --->
          <br>
          Page
          <cfinclude template="dpages2.cfm">          
          <!--- Show all link --->
          <cfoutput><a href="#cgi.SCRIPT_NAME#?showall=yes">Show All</a></cfoutput>
        </cfif>

</body>
</html>

<!----------------------------------------------------------
END FIRST PAGE
------------------------------------------------------------>


<!----------------------------------------------------------
START SECOND PAGE
------------------------------------------------------------>

<!--- Simple page counter starting at the first page --->
<cfset thispage = 1>

<!--- Loop thru row numbers --->
<cfloop from="1" to="#totalrows#" step="#rowsperpage#" index="pagerow">
<!--- Detect whether this page is currently being viewed --->
<cfset iscurrentpage = (pagerow GTE url.startrow) and (pagerow LTE endrow)>

<!--- If this is current page, show without link --->
<cfif iscurrentpage>
     <cfoutput><b>#thispage#</b></cfoutput>
<!--- Otherwise, show with link so user can go to page --->
     <cfelse>
     <cfoutput>
          <a href="#cgi.SCRIPT_NAME#?startrow=#pagerow#">#thispage#</a>
     </cfoutput>
</cfif>

<!--- Increment this page --->
<cfset thispage = thispage + 1>
</cfloop>

<!----------------------------------------------------------
END SECOND PAGE
------------------------------------------------------------>
ASKER CERTIFIED SOLUTION
Avatar of SidFishes
SidFishes
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Waller

ASKER

?
Ok, I'll try this out..
Thanks everyone!