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.
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> "
next
%>
<br />
<%
for i=1 to rs.PageCount
Response.Write "<a href=testSearch.asp?initial=" & initial & "&pg=" & i & ">" & i & "</a> "
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>