A class of ASP paging
Tested in 50,000 records, faster than the one in 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
Response.Write "Subject Number:" &mypage_recordtotal
Response.Write "</td>"
Response.Write "<td align=right>"
Response.Write "Pagination:"
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 ""
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 < Then
Formatcurrentstartpage = "0" & Currentstartpage
Else
Formatcurrentstartpage = Currentstartpage
End If
Response.Write "<a href= '" &MyPage_Url&strAnd& "mypage_pageno=" &CurrentStartPage& ">" &FormatCurrentStartPage& "</a>"
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) )-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 the Match in matches
Tmpmatch = Match.value
Readmypage_url = replace (Readmypage_url,tmpmatch, "")
Next
End Function
End Class
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service