Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to make a next link like this forum

Status
Not open for further replies.

5fe20041

Technical User
Joined
Feb 20, 2002
Messages
2
Location
TW
How to make a next link when page over 10 (just like this forum)?
For example:
page 1 2 3 4 5 6 7 8 9 10 next , (not 11)

Sorry!my English is very poor!I am a Chinese from Taiwan!

Thanks for help!
 
First, set a variable called "CurrentPage" like this:

<CFSET CURRENTPAGE=&quot;ProdDocList.cfm&quot;>

Next, do your query for the information you want to display.

Then, place this code after your query. I use this so much, I use a CFINCLUDE.
<!--- Set the number of records to display on each page. --->
<CFSET ONEACHPAGE = 10>

<!--- Set the default startrow to 1 if a value was not passed. --->
<!--- Determine whether or not to show the previous or next links. --->
<CFPARAM NAME = &quot;StartRow&quot; DEFAULT = &quot;1&quot;>
<!--- Set the value of endrow to the maxrows + startrow - 1 --->
<CFSET ENDROW = STARTROW + ONEACHPAGE - 1>
<!--- If the end row is greater than the recordcount, determine how many records are left. --->
<CFIF ENDROW GTE GETSEARCHINFO.RECORDCOUNT>
<CFSET ENDROW = GETSEARCHINFO.RECORDCOUNT>
<CFSET NEXT = FALSE>
<!--- Otherwise, set Next to true and determine the next set of records. --->
<CFELSE>
<CFSET NEXT = TRUE>
<CFIF ENDROW + ONEACHPAGE GT GETSEARCHINFO.RECORDCOUNT>
<CFSET NEXTNUM = GETSEARCHINFO.RECORDCOUNT - ENDROW>
<CFELSE>
<CFSET NEXTNUM = ONEACHPAGE>
</CFIF>
<CFSET NEXTSTART = ENDROW + 1>
</CFIF>
<!--- If StartRow is 1, set Previous to false. --->
<CFIF STARTROW IS 1>
<CFSET PREVIOUS = FALSE>
<!--- Othewise, determine the previous set of records. --->
<CFELSE>
<CFSET PREVIOUS = TRUE>
<CFSET PREVIOUSSTART = STARTROW - ONEACHPAGE>
</CFIF>

<!--- Determine how many pages will be displayed. --->
<CFSET NUMPAGES = CEILING(GETSEARCHINFO.RECORDCOUNT / ONEACHPAGE)>
<CFPARAM NAME = &quot;PageNum&quot; DEFAULT = &quot;1&quot;>

Finally, here is your navigation bar:

<CFOUTPUT>
<TABLE>
<TR>
<TD ALIGN=&quot;center&quot; VALIGN=&quot;middle&quot;> </TD>
<TD>
<!--- If Previous is true, display the previous link. --->
<CFIF PREVIOUS>
<A HREF =&quot;#CurrentPage#?StartRow=#PreviousStart#&PageNum=#DecrementValue(PageNum)#&quot;> « Previous</A>
</CFIF>
</TD>
<CFLOOP FROM = &quot;1&quot; TO = &quot;#NumPages#&quot; INDEX = &quot;ThisPage&quot;>
<CFIF THISPAGE IS PAGENUM>
<TD><B>[#ThisPage#]</B></TD>
<CFELSE>
<CFSET PAGENUMSTART = (((THISPAGE - 1) * ONEACHPAGE) + 1)>
<TD>
<A HREF =&quot;#CurrentPage#?StartRow=#PageNumStart#&PageNum=#ThisPage#&quot;> #ThisPage#</A></TD>
</CFIF>
</CFLOOP>
<TD>
<!--- If Next is true, display the previous link. --->
<CFIF NEXT>
<A HREF =&quot;#CurrentPage#?StartRow=#NextStart#&PageNum=#IncrementValue(PageNum)#&quot;> Next »</A>
</CFIF>
</TD>
</TR>
</TABLE>
</CFOUTPUT>

The only other important thing to to make sure you are passing all the variables you will need to do your query as URL variables in all three links in the navigation bar.

Good Luck!
Calista :-X
Jedi Knight,
Champion of the Force
 
Thanks for help.
I will try it.
 
Actually, I just re-read your post more carefully, and I realized that what I sent you will put all the pages, and not limit it to 10. My code should be a good start, at least. I'll have to think about that, bacause I may need to do the same thing you are trying to do. If you solve it, let me know, and I'll see what I can do. Calista :-X
Jedi Knight,
Champion of the Force
 
OK, I've got it! Here's the navigation bar, again. I cleaned it up a bit, but the changes are shown in red:

<CFOUTPUT>
<TABLE>
<TR>
<!--- If Previous is true, display the previous link. --->
<TD>
<CFIF PREVIOUS>
<A HREF =&quot;#CurrentPage#?StartRow=#PreviousStart#&PageNum=#DecrementValue(PageNum)#&quot;><<< Prev</A>
</CFIF>
</TD>

<CFIF #NumPages# GT 10>
<CFIF (#PageNum#+9) GT #NumPages#>
<CFSET FirstRecord=(#NumPages#-9)>
<CFSET LastRecord=#NumPages#>
<CFELSE>
<CFSET FirstRecord=#PageNum#>
<CFSET LastRecord=(#PageNum#+9)>
</CFIF>
<CFELSE>
<CFSET FirstRecord=1>
<CFSET LastRecord=#NumPages#>
</CFIF>
<CFLOOP FROM = &quot;#FirstRecord#&quot; TO = &quot;#LastRecord#&quot; INDEX = &quot;ThisPage&quot;>

<CFIF THISPAGE IS PAGENUM>
<TD><B>[#ThisPage#]</B></TD>
<CFELSE>
<CFSET PAGENUMSTART = (((THISPAGE - 1) * ONEACHPAGE) + 1)>
<TD>
<A HREF =&quot;#CurrentPage#?StartRow=#PageNumStart#&PageNum=#ThisPage#&quot;> #ThisPage#</A>
</TD>
</CFIF>
</CFLOOP>
<!--- If Next is true, display the previous link. --->
<CFIF NEXT>
<TD>
<A HREF =&quot;#CurrentPage#?StartRow=#NextStart#&PageNum=#IncrementValue(PageNum)#&quot;> Next >>></A>
</TD>
</CFIF>
</TR>
</TABLE>
</CFOUTPUT>

This will display a navigation bar of 10 pages no matter how many pages there are. Now, I'll see about &quot;Next 10&quot; and &quot;Prev 10&quot; links in addition to &quot;Next&quot; and &quot;Prev&quot;. Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top