Basic Methods for pagination of posts in ASP (1)

Source: Internet
Author: User

After learning about the above attributes and methods of the Recordset object, let's take a look at how to use them to achieve our paging display purpose. First, we can set a value for the PageSize attribute to specify the number of rows that constitute a page retrieved from the record group. Then, we can use the RecordCount attribute to determine the total number of records; divide the total number of records by PageSize to get the total number of displayed pages. Finally, you can access the specified page through the AbsolutePage attribute. It seems not complicated. Let's take a look at how the program is implemented?
We have established a simple BBS application. Its database has the following five fields: "ID", the automatic number of each post; "subject", the topic of each post; "name": the name of the post user; "email", the user's email address; "postdate": the time when the post is added. The database DSN is "bbs ". We put all the steps that show the pagination of the post in a process named "ShowList ()" for convenient calling. The procedure is as follows:
'---- Pagination of BBS posts ----
<Sub ShowList ()>
<
PgSz = 20': indicates the number of posts displayed on each page. The default value is 20 posts per page.
Set Conn = Server. CreateObject ("ADODB. Connection ")
Set RS = Server. CreateObject ("ADODB. RecordSet ")
SQL = "SELECT * FROM message order by ID DESC"
'Query all posts and sort them in reverse order by post ID
Conn. Open "bbs"
RS. open SQL, Conn, 1, 1
If RS. RecordCount = 0 then
Response. write "<P> <center> sorry, there is no relevant information in the database! </Center> </P>"
Else
RS. PageSize = Cint (PgSz) 'sets the value of the PageSize attribute.
Total = INT (RS. recordcount/PgSz *-1) *-1 'calculates the Total number of displayed pages
PageNo = Request ("pageno ")
If PageNo = "" Then
PageNo = 1
Else
PageNo = PageNo + 1
PageNo = PageNo-1
End if
ScrollAction = Request ("ScrollAction ")
If ScrollAction = "Previous Page" Then
PageNo = PageNo-1
End if
If ScrollAction = "next page" Then
PageNo = PageNo + 1
End if
If PageNo <1 Then
PageNo = 1
End if
N = 1
RS. AbsolutePage = PageNo
Response. Write "<CENTER>"
Position = RS. PageSize * PageNo
Pagebegin = position-RS.PageSize + 1
If position <RS. RecordCount then
Pagend = position
Else
Pagend = RS. RecordCount
End if
Response. Write "<P> <font color = 'navy'> <B> result of data database query: </B>"
Response. write "(total" & RS. recordCount & "displays information that meets the condition." & pagebegin & "-" & pagend & ") </font> </p>"
Response. Write "<table width = 600 BORDER = 1 CELLPADDING = 4 CELLSPACING = 0 BGCOLOR = # FFFFFF>"
Response. write "<tr bgcolor = #5FB5E2> <font size = 2> <TD> <B> subject </B> </TD> <B> User </B> </TD> <B> Email </B> </TD> <B> date of release </B> </TD> </FONT> <tr bgcolor = # FFFFFF>"


Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.