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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group Output by 10 Show next 10

Status
Not open for further replies.

DeZiner

Programmer
May 17, 2001
815
US
I have never needed this now I do, Please help.

I want to group results by ten, then have a link to show the next ten. I assume I need to use start row and maxrow. The problem I have is passing the search criteria to the second page to view results 11-20.

Good example is this forum.

Thanks in advanced for the help :)
 
Here is some code to get you started.This goes near the top of your page. Change "ONEACHPAGE" to whatever you want.
Code:
<!--- Set the number of records to display on each page. --->
<CFSET ONEACHPAGE = 20>

<!--- 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 GETDOCUMENTS.RECORDCOUNT>
    <CFSET ENDROW = GETDOCUMENTS.RECORDCOUNT>
    <CFSET NEXT = FALSE>
<!--- Otherwise, set Next to true and determine the next set of records. --->
<CFELSE>
    <CFSET NEXT = TRUE>
    <CFIF ENDROW + ONEACHPAGE GT GETDOCUMENTS.RECORDCOUNT>
        <CFSET NEXTNUM = GETDOCUMENTS.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(GETDOCUMENTS.RECORDCOUNT / ONEACHPAGE)>
<CFPARAM NAME = &quot;PageNum&quot; DEFAULT = &quot;1&quot;>
Here is where I actually display the data.
Code:
		<CFOUTPUT QUERY=&quot;GetDocuments&quot;  STARTROW=&quot;#StartRow#&quot; MAXROWS=&quot;#OnEachPage#&quot;>
		<CFIF #CURRENTROW# MOD 2 EQ 0>
			<CFSET COLOR=&quot;#Application.LightColor#&quot;>
		<CFELSE>
			<CFSET COLOR=&quot;#Application.Lighter#&quot;>
		</CFIF>
		<TABLE CLASS=&quot;MultiColor&quot;>
		<TR BGCOLOR=&quot;#Color#&quot;>
			<TD><A HREF=&quot;#DocLocation#&quot;>#DocTitle#</A></TD>
			<TD>#DocDescription#</TD>
		</TR>
		</TABLE>
		</CFOUTPUT>
		<TABLE CLASS=&quot;NavBar&quot;>
		    <TR>
		        <TD ALIGN=&quot;center&quot; VALIGN=&quot;middle&quot; WIDTH=&quot;20%&quot;> 
		            <!--- If Previous is true, display the previous link. --->
		            <CFIF PREVIOUS>
		                <CFOUTPUT>
		<A HREF =&quot;ListDocuments.cfm?StartRow=#PreviousStart#&PageNum=#DecrementValue(PageNum)#&quot;><SPAN CLASS=&quot;BigBlack&quot;> « Previous</SPAN></A>
		                </CFOUTPUT>
		            </CFIF>
		        </TD>
				<TD ALIGN=&quot;center&quot; VALIGN=&quot;middle&quot; WIDTH=&quot;60%&quot;>
		        <CFLOOP FROM = &quot;1&quot; TO = &quot;#NumPages#&quot; INDEX = &quot;ThisPage&quot;>
		            <CFOUTPUT>
		                <CFIF THISPAGE IS PAGENUM>
		                    <B>[#ThisPage#]</B>
		                <CFELSE>
		                    <CFSET PAGENUMSTART = (((THISPAGE - 1) * ONEACHPAGE) + 1)>
		<A HREF =&quot;ListDocuments.cfm?StartRow=#PageNumStart#&PageNum=#ThisPage#&quot;><SPAN CLASS=&quot;BigBlack&quot;> #ThisPage#</SPAN></A>
		                </CFIF>
		            </CFOUTPUT>
		        </CFLOOP>
				</TD>
		        <TD ALIGN=&quot;center&quot; VALIGN=&quot;middle&quot; WIDTH=&quot;20%&quot;>
		            <!--- If Next is true, display the previous link. --->
		            <CFIF NEXT>
		                <CFOUTPUT>
		<A HREF =&quot;ListDocuments.cfm?StartRow=#NextStart#&PageNum=#IncrementValue(PageNum)#&quot;><SPAN CLASS=&quot;BigBlack&quot;> Next »</SPAN></A>
		                </CFOUTPUT>
		            <CFELSE>
		                 
		            </CFIF>
		        </TD>
		    </TR>
		</TABLE>
Hope this helps! I got the basic code from this forum. Try searching this forum and you can probably find the original. Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top