Asp pagination class
Tested under 50,000 records, which is much faster than that of ado.
<%
'*************************************** **************************************** *****
'Specific usage
Dim strDbPath
Dim connstr
Dim mp
Set mp = New MyPage
StrDbPath = "fenye/db. mdb"
Connstr = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source ="
Connstr = connstr & Server. MapPath (strDbPath)
Set conn = Server. CreateObject ("Adodb. Connection ")
Conn. open connstr
Set rs = mp. Execute ("select * from table1", conn, 29)
While not rs. eof
Response. write rs ("aaaa") & "<br>"
Rs. MoveNext
Wend
Mp. pageDispaly ()
'*************************************** **************************************** *****
Class MyPage
Private MyPage_Conn, MyPage_StrSql, MyPage_TotalStrSql, MyPage_RS, MyPage_TotalRS
Private MyPage_PageSize
Private MyPage_PageAbsolute, MyPage_PageTotal, MyPage_RecordTotal
Private MyPage_Url
Public property let conn (strConn)
Set MyPage_Conn = strConn
End property
Public property let PageSize (intPageSize)
MyPage_PageSize = Cint (intPageSize)
End property
Public function PageExecute (strSql)
MyPage_PageAbsolute = MyPage_PageAbsoluteRequest ()
MyPage_TotalStrSql = FormatMyPage_TotalStrSql (strSql)
Set MyPage_TotalRS = MyPage_Conn.execute (MyPage_TotalStrSql)
MyPage_RecordTotal = MyPage_TotalRS ("total ")
MyPage_PageTotal = Cint (MyPage_RecordTotal/MyPage_PageSize)
MyPage_StrSql = FormatMyPage_StrSql (strSql)
Set MyPage_RS = MyPage_Conn.execute (MyPage_StrSql)
Dim I
I = 0
While not MyPage_RS.eof and I <(MyPage_PageAbsolute-1) * MyPage_PageSize
I = I + 1
MyPage_RS.MoveNext
Wend
Set PageExecute = MyPage_RS
End function
Public function Execute (strSql, strConn, intPageSize)
Conn = strConn
PageSize = intPageSize
Set Execute = PageExecute (strSql)
End function
Public function pageDispaly ()
MyPage_Url = ReadMyPage_Url
FirstPageTag = "<font face = webdings> 9 </font>" '| <
LastPageTag = "<font face = webdings >:</font>" '>>|
PreviewPageTag = "<font face = webdings> 7 </font>" '<
NextPageTag = "<font face = webdings> 8 </font>" '>
Dim strAnd
If instr (MyPage_Url ,"? ") = 0 then
StrAnd = "? "
Else
StrAnd = "&"
End if
Response. write "<table width = 100% border = 0 cellspacing = 0 cellpadding = 0>"
Response. write "<tr>"
Response. write "<td align = left>"
Response. write "Page:" & MyPage_PageAbsolute & "/" & MyPage_PageTotal & "Page & nbsp"
Response. write "number of topics:" & MyPage_RecordTotal
Response. write "</td>"
Response. write "<td align = right>"
Response. write "Paging :"
If MyPage_PageAbsolute> 10 then
Response. write "<a href = '" & MyPage_Url & strAnd & "MyPage_PageNo = 1'>" & firstPageTag & "</a>"
Response. write "<a href = '" & MyPage_Url & strAnd & "MyPage_PageNo =" & (MyPage_PageAbsolute-10) & "'>" & previewPageTag & "</a>"
Else
Response. write firstPageTag
Response. write previewPageTag
End if
Response. write "& nbsp"
Dim CurrentStartPage, I
I = 1
CurrentStartPage = (Cint (MyPage_PageAbsolute) \ 10) * 10 + 1
If Cint (MyPage_PageAbsolute) mod 10 = 0 then
CurrentStartPage = CurrentStartPage-10
End if
While I <11 and CurrentStartPage <MyPage_PageTotal + 1
If CurrentStartPage <10 then
FormatCurrentStartPage = "0" & CurrentStartPage
Else
FormatCurrentStartPage = CurrentStartPage
End if
Response. write "<a href = '" & MyPage_Url & strAnd & "MyPage_PageNo =" & CurrentStartPage & "'>" & FormatCurrentStartPage & "</a> & nbsp"
I = I + 1
CurrentStartPage = CurrentStartPage + 1
Wend
If MyPage_PageAbsolute <(MyPage_PageTotal-10) then
Response. write "<a href = '" & MyPage_Url & strAnd & "MyPage_PageNo =" & (MyPage_PageAbsolute + 10) & "'>" & nextPageTag & "</a>"
Response. write "<a href = '" & MyPage_Url & strAnd & "MyPage_PageNo =" & MyPage_PageTotal & "'>" & LastPageTag & "</a>"
Else
Response. write nextPageTag
Response. write LastPageTag
End if
Response. write ""
Response. write "</td>"
Response. write "</tr>"
Response. write "</table>"
End function
Public function GetPageNo ()
GetPageNo = cint (MyPage_PageAbsolute)
End function
Public function GetPageCount ()
GetPageCount = cint (MyPage_PageTotal)
End function
Public function GetPageNoName ()
GetPageNoName = "MyPage_PageNo"
End function
Public function GetPageSize ()
GetPageSize = MyPage_PageSize
End function
Public function GetRecordTotal ()
GetRecordTotal = MyPage_RecordTotal
End function
Private function FormatMyPage_TotalStrSql (strSql)
FormatMyPage_TotalStrSql = "select count (*) as total"
FormatMyPage_TotalStrSql = FormatMyPage_TotalStrSql & Mid (strSql, instr (strSql, "from "))
FormatMyPage_TotalStrSql = Mid (FormatMyPage_TotalStrSql, 1, instr (FormatMyPage_TotalStrSql & "order by", "order by")-1)
End function
Private function FormatMyPage_StrSql (strSql)
FormatMyPage_StrSql = replace (strSql, "select", "select top" & (MyPage_PageAbsolute * Cint (MyPage_PageSize )))
End function
Private function MyPage_PageAbsoluteRequest ()
If request ("MyPage_PageNo") = "" then
MyPage_PageAbsoluteRequest = 1
Else
If IsNumeric (request ("MyPage_PageNo") then
MyPage_PageAbsoluteRequest = request ("MyPage_PageNo ")
Else
MyPage_PageAbsoluteRequest = 1
End if
End if
End function
Private function ReadMyPage_Url ()
ReadMyPage_Url = Request. ServerVariables ("URL ")
If Request. QueryString <> "then
ReadMyPage_Url = ReadMyPage_Url &"? "& Request. QueryString
End if
Set re = new RegExp
Re. Pattern = "[& |?] MyPage_PageNo = \ d +? "
Re. IgnoreCase = true
Re. multiLine = true
Re. global = true
Set Matches = re. Execute (ReadMyPage_Url)
For Each Match in Matches
TmpMatch = Match. Value
ReadMyPage_Url = replace (ReadMyPage_Url, tmpMatch ,"")
Next
End function
End Class
%>