Super ASP big paging _ my class content I choose from the Blog of AppleBBS
Keyword: Super ASP, big paging _ my class, let me be the master
Source
<%
'================================================ ======================================
'Showmorepage ASP version
'Version HuangJM1.00
'Code by maomao
'Create Date 2004-09-28
'Qq: 5144707
'Http: // blog.csdn.net/maomaoysq
'Write for my lover: HuangJM 'This program can be used and modified for free, but please keep the above information
'
'Function
'The program encapsulates the data paging part, and the data display part is completely customized by the user,
'Multiple URL parameters are supported: http: // www. ***. com/***. asp? Aa = 1 & page = 9 & bb = 2
'
'
'Paramers:
'Papgesize defines the number of records per page.
'Getcurpagenum returns the number of record sets on the current page. This attribute is read-only.
'Getrs returns the paged Recordset. This attribute is read-only.
'Getconn get database connection
'Getsql: query statement obtained
'Interface of Class
'Showpage display pagination navigation bar, the only public Method
'
############# Class call example #################
'Create object
'Set hjmPage = new ShowMorePage
'Get database connection
'Hjmpage. getconn = conn
'SQL statement
'Hjmpage. getsql = "select * from shop_books where newsbook = 1 order by bookid desc"
'Set 20 records per page. 10 records are displayed by default.
'Hjmpage. pagesize = 20
'Display paging information, which can be called at any location and multiple times
'Hjmpage. showpage ()
'Set rs = hjmPage. getrs () 'returns Recordset
'Show data start
'Here you can customize the display mode.
'For I = 1 to hjmPage. GetCurPageNum' number of records on the current page
'Response. write left (trim (rs ("bookname"), 13 )&"...."
'Rs. movenext
'Next
'Show data end
'Set hjmPage = nothing
############# Class call example #################
'================================================ ======================================
Const Btn_First = "<font face =" "webdings"> 9 </font> "'defines the display style of the button on the first page.
Const Btn_Prev = "<font face =" "webdings"> 3 </font> "'defines the display style of buttons on the previous page.
Const Btn_Next = "<font face =" "webdings"> 4 </font> "'defines the display style of the next page button
Const Btn_Last = "<font face =" "webdings" >:</font> "'defines the button display style on the last page.
Const XD_Align = "Center" 'defines the page information alignment Mode
Const XD_Width = "100%" 'defines the size of the page information box
Class ShowMorePage
Private Obj_Conn, Obj_Rs, Str_ SQL, int_PageSize, Str_Errors, Int_CurPage, Str_URL, Int_TotalPage, Int_TotalRecord
'================================================ ======================================
'Pagesize Property
'Set the page size for each page
'================================================ ======================================
Public Property Let PageSize (intvalue)
If IsNumeric (intvalue) Then
Int_PageSize = CLng (intvalue)
Else
Str_Errors = Str_Errors & "The PageSize parameter is incorrect"
ShowError ()
End If
End Property
Public Property Get PageSize
If int_PageSize = "" or (not (IsNumeric (int_PageSize) Then
PageSize = 10
Else
PageSize = int_PageSize
End If
End Property
'================================================ ======================================
'Getrs attributes
'Return the record set after pagination
'================================================ ======================================
Public Property Get GetRs ()
If Int_TotalRecord = 0 then Call GetPage ()
If not (Obj_Rs.eof and Obj_Rs.BOF) Then
If Int_CurPage <> 1 then
If Int_CurPage-1 <Int_TotalPage then
Obj_Rs.move (Int_CurPage-1) * PageSize
Dim bookmark
Bookmark = Obj_Rs.bookmark
Else
Int_CurPage = 1
End if
End if
End If
Set GetRs = Obj_Rs
End Property
'================================================ ======================================
'Getcurpagenum Property
'Return the number of record sets on the current page
'================================================ ======================================
Public Property Get GetCurPageNum ()
Dim int_PageNum
Int_PageNum = int_PageSize
If Int_TotalRecord = 0 then Call GetPage ()
If Int_CurPage> Int_TotalPage Then
Int_CurPage = Int_TotalPage
Int_PageNum = Int_TotalRecord-(Int_TotalPage-1) * int_PageSize
ElseIf Int_CurPage = Int_TotalPage Then
Int_PageNum = Int_TotalRecord-(Int_TotalPage-1) * int_PageSize
End If
GetCurPageNum = int_PageNum
End Property
'================================================ ======================================
'Getconn get database connection
'
'================================================ ======================================
Public Property Let GetConn (sconn)
Set Obj_Conn = sconn
End Property
'================================================ ======================================
'Getsql: query statement obtained
'
'================================================ ======================================
Public Property Let GetSQL (svalue)
Str_ SQL = svalue
End Property
'================================================ ======================================
'Class _ Initialize Class initialization
'Initialize the value of the current page
'
'================================================ ======================================
Private Sub Class_Initialize
'====================================
'Set the token value for some parameters
'====================================
Int_PageSize = 10' sets the default value of the page to 10.
Int_TotalRecord = 0
'====================================
'Get the current value
'====================================
If request ("page") = "" Then
Int_CurPage = 1
ElseIf not (IsNumeric (request ("page") Then
Int_CurPage = 1
ElseIf CInt (Trim (request ("page") <1 Then
Int_CurPage = 1
Else
Int_CurPage = CInt (Trim (request ("page ")))
End If
End Sub
'================================================ ==================================
'Openrs open the dataset
'The Home Page, Previous Page, next page, last page, and digital navigation
'
'================================================ ==================================
Private Sub openRS ()
Set Obj_Rs = Server. createobject ("adodb. recordset ")
Obj_Rs.Open Str_ SQL, Obj_Conn, 1, 1
End Sub
'================================================ ==================================
'Getpage' creates a paging navigation bar.
'The Home Page, Previous Page, next page, last page, and digital navigation
'
'================================================ ==================================
Private Sub GetPage ()
If TypeName (Obj_Rs) <> "Object" Then Call openRS ()
Int_TotalRecord = Obj_Rs.RecordCount
If Int_TotalRecord <= 0 Then
Str_Errors = Str_Errors & "the total number of records is zero. Please input data"
Call ShowError ()
End If
If Int_TotalRecord mod PageSize = 0 Then
Int_TotalPage = Int_TotalRecord \ int_PageSize
Else
Int_TotalPage = Int_TotalRecord \ int_PageSize + 1
End If
If Int_CurPage> Int_TotalPage Then
Int_CurPage = Int_TotalPage
End If
End Sub
'================================================ ==================================
'Showpage creates a paging navigation bar
'The Home Page, Previous Page, next page, last page, and digital navigation
'
'================================================ ==================================
Public Sub ShowPage ()
Dim str_tmp
Str_URL = GetUrl ()
If Int_TotalRecord = 0 then Call GetPage ()
'================================================ ======================================
'Display paging information. Each module can change the explicit position as required.
'================================================ ======================================
Response. write ""
Str_tmp = ShowFirstPrv
Response. write str_tmp
Str_tmp = showNumBtn
Response. write str_tmp
Str_tmp = ShowNextLast
Response. write str_tmp
Str_tmp = ShowPageInfo
Response. write str_tmp
Response. write ""
End Sub
'================================================ ==================================
'Showfirstprv: display the home page and the previous page
'
'
'================================================ ==================================
Private function ShowFirstPrv ()
Dim Str_tmp, int_prvpage
If Int_CurPage = 1 Then
Str_tmp = Btn_First & "& Btn_Prev
Else
Int_prvpage = Int_CurPage-1
Str_tmp = "<a href =" "& Str_URL &" 1 "&" ">" & Btn_First & "</a> <a href =" "& Str_URL & CStr (int_prvpage) & ""> "& Btn_Prev &" </a>"
End If
ShowFirstPrv = str_tmp
End function
'================================================ ==================================
'Shownextlast next and last pages
'
'
'================================================ ==================================
Private function ShowNextLast ()
Dim str_tmp, int_Nextpage
If Int_CurPage> = Int_TotalPage Then
Str_tmp = Btn_Next & "& Btn_Last
Else
Int_NextPage = Int_CurPage + 1
Str_tmp = "<a href =" "& Str_URL & CStr (int_nextpage) & ">" & Btn_Next & "</a> <a href =" & Str_URL & CStr (Int_TotalPage) & ""> "& Btn_Last &" </a>"
End If
ShowNextLast = str_tmp
End function
'================================================ ==================================
'Shownumbtn digital navigation
'10 pages are displayed each time
'
'================================================ ==================================
Private function showNumBtn ()
Dim I, str_tmp, m, n
M = Int_CurPage-4
N = Int_TotalPage
If n> 1 then
For I = 1 to 10
If m <1 then m = 1
If m> n then
Exit
End if
Str_tmp = str_tmp & "[<a href =" & Str_URL & CStr (I) & ""> "& I &" </a>]"
M = m + 1
Next
End if
ShowNumBtn = str_tmp
End function
'================================================ ==================================
'Showpageinfo page information
'Modify as required
'
'================================================ ==================================
Private function ShowPageInfo ()
Dim str_tmp
Str_tmp = "Page times:" & Int_CurPage & "/" & Int_TotalPage & "Page total" & Int_TotalRecord & "record" & int_PageSize & "/page"
ShowPageInfo = str_tmp
End function
'================================================ ======================================
'Geturl: Get the current URL.
'Obtain different results based on different URL parameters
'
'================================================ ======================================
Private function GetURL ()
Dim strUrl, tmp_URL, I, j, search_str, result_url
Search_str = "page ="
StrUrl = Request. Servervariables ("URL ")
StrUrl = split (strUrl ,"/")
I = UBound (strUrl, 1)
Tmp_URL = strUrl (I) 'to get the file name of the current page
Str_params = Trim (Request. Servervariables ("QUERY_STRING "))
If str_params = "" Then
Result_url = tmp_URL &"? Page ="
Else
If limit Rev (str_params, search_str) = 0 Then
Result_url = tmp_URL &"? "& Str_params &" & page ="
Else
J = Limit Rev (str_params, search_str)-2
If j =-1 Then
Result_url = tmp_URL &"? Page ="
Else
Str_lparams = Left (str_params, j)
Str_rparams = right (str_params, len (str_params)-J-1)
If InStr (str_rparams, "&") <> 0 then
Str_rparams = right (str_rparams, len (str_rparams)-InStr (str_rparams, "&") + 1)
Else
Str_rparams = ""
End if
Result_url = tmp_URL &"? "& Str_lparams & str_rparams &" & page ="
End If
End If
End If
GetURL = result_url
End function
'================================================ ==================================
'Set the Terminate event.
'
'================================================ ==================================
Private Sub Class_Terminate
Obj_Rs.close
Set Obj_Rs = nothing
Obj_Conn.close
Set Obj_Conn = nothing
End Sub
'================================================ ==================================
'Showerror error message
'
'
'================================================ ==================================
Private Sub ShowError ()
If Str_Errors <> "" Then
Response. Write ("" & Str_Errors &"")
Response. End
End If
End Sub
End class
%>
<! -- # Include file = "include/function. asp" -->
<%
Dim conn
Call dbconnect ()
############# Class call example #################
'Create object
Set hjmPage = new ShowMorePage
'Get database connection
HjmPage. getconn = conn
'SQL statement
HjmPage. getsql = "select Top 6 * from shop_books where newsbook = 1 order by bookid desc"
'Set the number of records on each page to 5.
HjmPage. pagesize = 2
Set rs = hjmPage. getrs () 'returns Recordset
'Display paging information. This method can be called at any location after set rs = hjmPage. getrs (). It can be called multiple times.
HjmPage. showpage ()
'Display data
Response. Write ("<br/> ")
For I = 1 to hjmPage. GetCurPageNum 'number of records on the current page
'Here you can customize the display mode.
%>