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

How do you break-down a search result into multiple pages?

Status
Not open for further replies.

Muhsin

Technical User
Nov 16, 2002
5
US
Hi,

I am trying to create a search results page where I would like to view results in groups of say 5.

For ex: If I have a search result of 17 results and I am viewing results in groups of 5. I would like to have a link at the bottom of the first 5 results to go to the remaining results. So in this case, I would like to see View results 6-10, 11-15, 16-17

Note: For the last result range I would like to see 16 - 17 and NOT 16 - 20.

Any suggestions in this regards would be greatly appreciated.

Thank you.
 
Hey Muhsin,

The basic steps in this are:

1. Use <cfparam name=&quot;start&quot; default=&quot;1&quot;> to create page variable to keep track of where you are.

2. Calculate your start and end records similar to this:
<cfif start lt 1><cfset start=1></cfif> <!--- basic error checking --->
<cfset end=start+4>
<cfif end gt query1.recordcount><cfset end=query1.recordcount></cfif>

3. Use <cfloop query=&quot;query1&quot; startRow=#start# endRow=#end#><cfoutput> to loop through your records.

4. Make links to the next and previous pages similar to this:
<cfif (end+5 ) gt query1.recordcount><cfset end=query1.recordcount-5></cfif>
<cfif start gt 1>
<a href=&quot;page.cfm?start=#evaluate(start-5)#>
Previous #evaluate(start-5)# - #evaluate(start-1)#
</a>
</cfif>
<cfif end lt query1.recordcount>
<a href=&quot;page.cfm?start=#evaluate(start+5)#&quot;>
Next #evaluate(start+5)# - #evaluate(end+5)#
-</a>
</cfif>

You can modify the last step a lot to customize how your next and previous links work but this should get you started.

Let me know if you have any problems with it as I didn't test this.
GJ
 
Thanks, for your help.

I'll start working on it now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top