<% ' usage
Dim Pages ' Defining class variables
Set Pages = New cls_pages_new
Pages.intpage= page ' current page number
Pages.requestpage = 10 ' number of page turns per page
pages.shownum=10 ' number of records displayed per page
Pages.other = zr.querystring ' Multiple URL variables
Rs = Pages.resultset (SQL) class output results
Recordcount=pages.intrecun ' Total record count
If IsNull (rs) then Rs = "<br> Nothing" ' is empty then no record
If IsArray (RS) Then
For i=0 to UBound (rs,2)
' Loop body content as result output
Next
End If
%>
<%=pages.showpages ()%> paging output
<%
Class cls_pages_new
Private Intrspagesize,intpacun,intpagecun,intpagedown,intpageup,page
Private Rs,tother
Public Intrecun
' Initialize
Private Sub Class_Initialize ()
Intrspagesize=20 ' number of records displayed per page
intpagecun=10 ' How many pages per page
Intrecun=-1 ' Total record count
End Sub
' End
Private Sub Class_Terminate ()
End Sub
' Get current page
Public Property Let Intpage (ByVal vshownum)
Page=checknum (vshownum,10,-1)
If IsNumeric (page) Then ' page number is an integer
Page=cint (page)
If Page<1 then page=1
Else
Page=1
End If
End Property
' Gets the number of bars per page
Public Property Let Shownum (ByVal vshownum)
Intrspagesize=checknum (vshownum,10,-1)
End Property
' Get pages per page
Public Property Let Requestpage (ByVal vshownum)
Intpagecun=checknum (vshownum,10,-1)
End Property
' Get other parameters on the URL
Public Property Let other (ByVal Tor)
If tor= "" Or IsNull (Tor) Then
Tother= ""
Else
Tother=tor & "&"
End If
End Property
' Output result array
Public Property Get ResultSet (ByVal sql)
Resultset=null
If not IsObject (Conn) then Connectiondatabase
Set Rs = Server.CreateObject ("Adodb.recordset")
Rs.cursorlocation = 3
On Error Resume Next
Rs.Open sql,conn,1,1,&h0001 ' &h0001 represents adCmdText, will execute a sql,&h0002 for adCmdTable, and will manipulate a table
If ERR Then
Err. Clear
Set Conn = Nothing
Response.Write "When querying for data, please check that your query code is correct. "
Response.End
End If
If not rs.eof Then
Rs.pagesize=intrspagesize
Intrecun=rs.recordcount ' Total record count
Intpacun=rs.pagecount ' Total pages
Rs.absolutepage=page
Resultset=rs.getrows (Intrspagesize)
End If
Rs.close
Set rs=nothing
' Rs.absoluteposition = (TmpPage-1) * Tshownum + 1
Zr.sqlquerynum = zr.sqlquerynum+1
End Property
‘
Private Function checknum (byVal istr,byval istartnum,byval iendnum)
If not IsNumeric (ISTR) Then
Checknum=istartnum
Else
CHECKNUM=CLNG (ISTR)
End If
If Iendnum>-1 Then
If Checknum<istartnum then Checknum=istartnum
If Checknum>iendnum then Checknum=iendnum
End If
End Function
' Show pagination columns
Public Function showpages ()
Dim HTMLText
If Intpacun<intpagecun then Intpagecun=intpacun
If page<>1 Then ' show first page
htmltext=htmltext& "<a href=" "?" &TOther& "page=1" "title=" "first page" "><font style=" "Font-family:webdings" ">9</font></a>" &CHR (&CHR) (10)
Else
htmltext=htmltext& "<font style=" "Font-family:webdings" ">9</font>" &CHR (10)
End If
If Page>intpagecun Then ' show on multiple pages
htmltext=htmltext& "<a href=" "?" &TOther& "page=" &page-intPageCun& "" title= "on" &intPageCun& "page" "><font style=" " Font-family:webdings ">7</font></a>" &CHR (&CHR) (10)
Else
htmltext=htmltext& "<font style=" "Font-family:webdings" ">7</font>" &CHR (10)
End If
If page>1 Then ' show Previous page
htmltext=htmltext& "<a href=" "?" &TOther& "page=" &page-1& "" "title=" "Previous page" "><font style=" "Font-family:webdings" ">3</ Font></a> "&CHR (&CHR) (10)
Else
htmltext=htmltext& "<font style=" "Font-family:webdings" ">3</font>" &CHR (10)
End If
If intpagecun MoD 2 =1 Then
intpageup= (intPageCun-1)/2
Intpagedown=intpageup
Else
Intpageup=intpagecun/2-1
Intpagedown=intpageup+1
End If
If Page<=intpageup Then
Intpageup=page-1
Intpagedown=intpagecun-intpageup-1
End If
If (intpacun-page) <=intpagedown Then
Intpagedown= (Intpacun-page)
Intpageup=intpagecun-intpagedown-1
End If
For I=intpageup to 1 Step-1
htmltext=htmltext& "<a href=" "?" &TOther& "page=" & (page-i) & "" "Title=" "" & (Page-i) & "page" > "& (Page-i) &" </a> "&CHR (&CHR) (10)
Next
htmltext=htmltext& "<font>" &page& "</font>" &CHR (&CHR) (10) ' current page
For I=1 to Intpagedown
htmltext=htmltext& "<a href=" "?" &TOther& "page=" & (page+i) & "" "Title=" "" & (Page+i) & "page" > "& (Page+i) &" </a> "&CHR (&CHR) (10)
Next
If Page<intpacun Then ' show next page
htmltext=htmltext& "<a href=" "?" &TOther& "page=" &page+1& "" "title=" "Next" "><font style=" "Font-family:webdings" ">4</ Font></a> "&CHR (&CHR) (10)
Else
htmltext=htmltext& "<font style=" "Font-family:webdings" ">4</font>" &CHR (10)
End If
If Page<intpacun-intpagecun Then ' show next multiple pages
htmltext=htmltext& "<a href=" "?" &TOther& "page=" &page+intPageCun& "" title= "under" &intPageCun& "page" "><font style=" " Font-family:webdings ">8</font></a>" &CHR (&CHR) (10)
Else
htmltext=htmltext& "<font style=" "Font-family:webdings" ">8</font>" &CHR (10)
End If
If Page<>intpacun Then ' show last page
htmltext=htmltext& "<a href=" "?" &TOther& "page=" &intPaCun& "" "title=" "last Page" "><font style=" "Font-family:webdings" ">:</ Font></a> "&CHR (&CHR) (10)
Else
htmltext=htmltext& "<font style=" "Font-family:webdings" ">:</font>" &CHR (10)
End If
Showpages=htmltext
End Function
End Class
%>
Pagination Display class source code