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

Search Results Page 2

Status
Not open for further replies.

khurram

IS-IT--Management
Jan 10, 2001
95
CA
I am creating a search page that shows 1-25 records per page. I want to have the following format at the bottom of each page so that users can see more results:

1 [2] 3 4 5 6 7 8 9 10

Where [2] represents records 26-50 being displayed and the rest able to be displayed.

Thanks in advance.

Khurram
 
Thats a very complicated answer. You might try building the dynamic navigation piece first since incorporating a search query and its output content is a totally different issue.

Try querying just 5 records, and seperate each record into a different page. Pass the ID from the table in the URL, but make the list of page numbers 1, 2, 3.. making the ID transparent to the user.

You'll have to build an array of the output records IDs. (could also use lists) Then loop through that list / array and build a variable called #navigation# by appending HTML to it every iteration.

<cfloop from=1 to=#listLen(navlist)# index=i>
<cfset navigation = navigation & '<a href=&quot;?ID=#navArray[1]#>#i#</a> &nbsp;'>
</cfloop>

See how you do on one record per page... then move on to multiple records per page.

 
I don't remember where I got this script, but it does exactly what you want.






<cfquery name=&quot;getsearchinfo&quot; datasource=&quot;yourDSN&quot;>
INSERT yourSQL HERE
</cfquery>




<!--- Set the number of records to display on each page. --->
<cfset oneachpage = 25>

<!--- 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;>

<table border=&quot;0&quot;>
<tr>
<td align=&quot;center&quot; valign=&quot;middle&quot;> </td>
<td>
<!--- If Previous is true, display the previous link. --->
<cfif previous>
<cfoutput>
<a href =&quot;yourCFML.cfm?StartRow=#PreviousStart#&PageNum=#DecrementValue(PageNum)#&quot;> « Previous</a>
</cfoutput>
<cfelse>
 
</cfif>
</td>
<cfloop from = &quot;1&quot; to = &quot;#NumPages#&quot; index = &quot;ThisPage&quot;>
<cfoutput>
<cfif thispage is pagenum>
<td><b>[#ThisPage#]</b></td>
<cfelse>
<cfset pagenumstart = (((thispage - 1) * oneachpage) + 1)>
<td>
<a href =&quot;yourCFML.cfm?StartRow=#PageNumStart#&PageNum=#ThisPage#&quot;> #ThisPage#</a></td>
</cfif>
</cfoutput>
</cfloop>
<td>
<!--- If Next is true, display the previous link. --->
<cfif next>
<cfoutput>
<a href =&quot;yourCFML.cfm?StartRow=#NextStart#&PageNum=#IncrementValue(PageNum)#&quot;> Next »</a>
</cfoutput>
<cfelse>
 
</cfif>
</td>
</tr>
</table>



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top