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!

Recordset paging properties

Status
Not open for further replies.

snowneil

Programmer
Mar 22, 2006
40
GB
Below is the test code i have done so far.
I want to clean it up a bit and there are a few problems i want to ask about.

I have used a record counter to limit the records instead of using .PageSize correctly, the main reason for this is i was having problems with the last page because the records were less than 30.

Each time the page is refreshed the recordset returns all records for that initial, which is inefficient.

If anyone has some tips or changes to the below please let me know.

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Response.Buffer=true %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Customer Test Search</title>
</head>

<body>
<%
dim rs,i,strConn,strTemp, initial,recordCounter,counter,screenColour, alphaArray
set rs=server.CreateObject("adodb.recordset") 

rs.CursorLocation=3 'clientside
rs.CursorType=3 'staticrecordset
rs.PageSize=30

recordCounter=0
counter=0
strConn="<Dbase details>"

initial = Request.QueryString("initial")
alphaArray = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
			
for i=0 to 24
	if initial = alphaArray(i) then
		strTemp = "SELECT id,firstname,surname,postcode FROM Customer WHERE surname LIKE '" & initial & "%' ORDER BY surname ASC"
	End if
next
	
rs.Open strTemp, strConn 

for i=0 to 25
	Response.Write "<a href=testSearch.asp?initial=" & alphaArray(i) & "&pg=1>" & alphaArray(i) & "</a>&nbsp;"
next
%>
<br />
<%
for i=1 to rs.PageCount
	Response.Write "<a href=testSearch.asp?initial=" & initial & "&pg=" & i & ">" & i & "</a>&nbsp;"
next

%>
	<br />
	<table border="0" cellpadding="0" cellspacing="0">
				<tr class="header">
					<td width="5%">ID</td>
					<td width="20%">Name</td>
					<td width="10%">Postcode</td>
					<td width="5%">View</td>
				</tr> 
<%

rs.AbsolutePage=cint(Request.QueryString("pg"))

Do while NOT rs.EOF
	if recordCounter < 30 then
			if counter = 0 then
				screenColour="#E4DEF8"
			else
				screenColour="#ffffff"
			end if
		%>
				<tr>
					<td bgcolor="<%=screenColour%>"><%= rs("id")%></td>
					<td bgcolor="<%=screenColour%>"><%= rs("firstname") & " " & rs("surname")%></td>
					<td bgcolor="<%=screenColour%>"><%= rs("postcode")%></td>
					<td bgcolor="<%=screenColour%>">
						<div align="center"><a href="customerDetails.asp?cstId=<%= rs("id")%>&stage=start"><img src="../includes/images/viewMag.gif" width="15" height="15" border="0"></a>
					</div></td>
				</tr>		
		<%		
		counter=counter+1
		
		
		if counter > 1 then
			counter=0
		end if
	End if
	
	rs.MoveNext
	recordCounter=recordCounter+1
Loop

if recordCounter = 0 then
%>
	<tr>
		<td bgcolor="#E4DEF8" colspan="6">There are no customers matching your criteria...</td>
	</tr>
<%
end if
%>
	    </table>
<%
	rs.Close
%>
</body>
</html>
 
Correction to this bit of code
Code:
for i=0 to [COLOR=red]25[/color]
    if initial = alphaArray(i) then
        strTemp = "SELECT id,firstname,surname,postcode FROM Customer WHERE surname LIKE '" & initial & "%' ORDER BY surname ASC"
    End if
next
 
I'd personally go with .PageSize for paging. It works like a champ for me. Good luck.
 
Yea that is what i am trying to do at the moment, i am just not sure how to get it working correctly.

In the code above i have set the rs.PageSize, which gives me the right number of pages but then i have used a recordCounter variable.

The problem i have is that each time page 1 is clicked it returns the full recordset and only displays the first 20, if page 2 is clicked it returns the full recordset again minus the first 20 records and displays records 20-40.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top