Paging
Hvordan laver jeg en paging af et recordset? Se nedenstående kode. Hvad gør jeg galt?<% Response.Buffer = True %>
<html><head>
<title>Søgeresultat</title>
<body background="grey_bricks1.gif" text="#FFFFFF">
<%
strKeyword = Trim(Request.Form("Keyword"))
If Len(strKeyword) = 0 Then
Response.Clear
Response.Redirect("search.htm")
Else
strKeyword = Replace(strKeyword,"'","''")
End If
intPage = Request("page")
If isNumeric(intPage) = False Or intPage < 1 Then
intPage = 1
End If
strSQL = "SELECT ID, f1, f2, f3 FROM Tabel WHERE"
strSQL = strSQL & " (f1 LIKE '%" & strKeyword & "%')"
strSQL = strSQL & " OR (f2 LIKE '%" & strKeyword & "%')"
strSQL = strSQL & " OR (f3 LIKE '%" & strKeyword & "%')"
strDSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.Mappath ("Base.mdb")
Set myConn = Server.CreateObject("ADODB.Connection")
myConn.Open strDSN
Set rs = myConn.Execute(strSQL)
If Not (rs.BOF Or rs.EOF) Then
rs.PageSize = 10
rs.AbsolutePage = intPage
intRecCount = rs.PageSize
intPageCount = rs.PageCount
Response.Write "<p><b>Side " & intPage & " af " & intPageCount & "</b></p>"
Do While Not rs.EOF And intRecCount > 0
countSQL = "SELECT Count(*) As found from Tabel WHERE"
countSQL = countSQL & " (f1 LIKE '%" & strKeyword & "%')"
countSQL = countSQL & " OR (f2 LIKE '%" & strKeyword & "%')"
countSQL = countSQL & " OR (f3 LIKE '%" & strKeyword & "%')"
Set count = myConn.Execute(countSQL)
Response.Write "<p><b><font face=Arial><font size=4><font color=#FFFFFF>Din søgning resulterede i "&count("found")&" hits</b></p>"
Response.Write "<p><b><font face=Arial><font size=10><font color=#FFFFFF>Søgeresultat</b></p>"
Response.Write "<font color=#FFFFFF><table border=8>"
Response.Write "<cellPadding=8>"
Response.Write "<cellSpacing=8>"
Response.Write "<tr><th>f1</th><th>f2</th><th>f3</th></tr>"
Do While Not rs.EOF
Response.Write "<tr><td>" & rs("f1") & "</td>"
Response.Write "<td>" & rs("f2") & "</td>"
Response.Write "<td>" & rs("f3") & "</td>"</tr>"
intRecCount = intRecCount - 1
rs.MoveNext
Loop
End If
Response.Write "</table>"
rs.Close
Set rs = Nothing
Response.Write "<p>Gå til side "
For intNum = 1 To intPageCount
Response.Write "<a href=paging.asp?page=" & intNum & ">" & intNum & "</a> "
Next
Response.Write "<p>"
If Clng(intPage) > 1 Then
Response.Write "<a href=paging.asp?page=" & intPage - 1 & "><<</a>"
Else
Response.Write "<<"
End If
Response.Write " "
If Clng(intPage) < Clng(intPageCount) Then
Response.Write "<a href=paging.asp?page=" & intPage + 1 & ">>></a> "
Else
Response.Write ">>"
End If
rem Else
rem Response.Write "<p>Der er ikke fundet nogle hits i denne søgning</p>"
rem End If
rem myConn.Close
rem Set myConn = Nothing
%>
</body></html>