|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Recordset Navigation Question
I am building a simple search feature, searching by last name. The results will be very large and I am trying to display 10 results at a time. Everything works fine until I try to go the the second page. For example, my original search result is 100 records, out of a total of 5000. The result displays Records 1 to 10 of 100. I click on the pointer to go to page 2 and the display changes to 11 out of 5000 and starts from the beginning of the alphabet. What am I overlooking?
Thanks in advance... <cfset CurrentPage=GetFileFromPath(GetTemplatePath())> <cfparam name="form.LName" default=""> <cfparam name="PageNum_qryGetLawyer" default="1"> <cfquery name="qryGetLawyer" datasource="Lawyer1"> SELECT UserID, FNAME, LNAME, Firm, CITY, STATE, ZIP FROM dbo.tblLawyers WHERE LNAME LIKE '#Form.LName#%' ORDER BY LNAME ASC </cfquery> <cfset MaxRows_qryGetLawyer=10> <cfset StartRow_qryGetLawyer=Min((PageNum_qryGetLawyer-1)*MaxRows_qryGetLawyer+1,Max(qryGetLawyer.RecordCount,1))> <cfset EndRow_qryGetLawyer=Min(StartRow_qryGetLawyer+MaxRows_qryGetLawyer-1,qryGetLawyer.RecordCount)> <cfset TotalPages_qryGetLawyer=Ceiling(qryGetLawyer.RecordCount/MaxRows_qryGetLawyer)> <cfset QueryString_qryGetLawyer=Iif(CGI.QUERY_STRING NEQ "",DE("&"&XMLFormat(CGI.QUERY_STRING)),DE(""))> <cfset tempPos=ListContainsNoCase(QueryString_qryGetLawyer,"PageNum_qryGetLawyer=","&")> <cfif tempPos NEQ 0> <cfset QueryString_qryGetLawyer=ListDeleteAt(QueryString_qryGetLawyer,tempPos,"&")> </cfif> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <table border="1" cellpadding="3"> <tr> <td>UserID</td> <td>FNAME</td> <td>LNAME</td> <td>Firm</td> <td>CITY</td> <td>STATE</td> <td>ZIP</td> </tr> <cfoutput query="qryGetLawyer" startrow="#StartRow_qryGetLawyer#" maxrows="#MaxRows_qryGetLawyer#"> <tr> <td>#qryGetLawyer.UserID#</td> <td>#qryGetLawyer.FNAME#</td> <td>#qryGetLawyer.LNAME#</td> <td>#qryGetLawyer.Firm#</td> <td>#qryGetLawyer.CITY#</td> <td>#qryGetLawyer.STATE#</td> <td>#qryGetLawyer.ZIP#</td> </tr> </cfoutput> </table> <table border="0" width="50%" align="center"> <cfoutput> <tr> <td width="23%" align="center"><cfif PageNum_qryGetLawyer GT 1> <a href="#CurrentPage#?PageNum_qryGetLawyer=1#QueryString_qryGetLawyer#"><img src="First.gif" border=0></a> </cfif> </td> <td width="31%" align="center"><cfif PageNum_qryGetLawyer GT 1> <a href="#CurrentPage#?PageNum_qryGetLawyer=#Max(DecrementValue(PageNum_qryGetLawyer),1)##QueryString_qryGetL awyer#"><img src="Previous.gif" border=0></a> </cfif> </td> <td width="23%" align="center"><cfif PageNum_qryGetLawyer LT TotalPages_qryGetLawyer> <a href="#CurrentPage#?PageNum_qryGetLawyer=#Min(IncrementValue(PageNum_qryGetLawyer),TotalPages_qryGetLawyer )##QueryString_qryGetLawyer#"><img src="Next.gif" border=0></a> </cfif> </td> <td width="23%" align="center"><cfif PageNum_qryGetLawyer LT TotalPages_qryGetLawyer> <a href="#CurrentPage#?PageNum_qryGetLawyer=#TotalPages_qryGetLawyer##QueryString_qryGetLawyer#"><img src="Last.gif" border=0></a> </cfif> </td> </tr> </cfoutput> </table> <cfoutput>Records #StartRow_qryGetLawyer# to #EndRow_qryGetLawyer# of #qryGetLawyer.RecordCount# </cfoutput> |
|
#2
|
|||
|
|||
|
Too much code there for me to look through quickly. But I'd try narrowing the records returned in the actual SQL statement than rerunning the entire SQL statement on every page request. Just pass the last ID viewed on the previous page and use it in your where clause. You can limit the number returned using the TOP SQL command or with the MAXROWS attribute of CFQUERY.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Recordset Navigation Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|