It should be said that I learned how to insert records and how to display records, so now the simple and complete article system, news system and message system are not a problem. Then the following problem is: as the content of the information increases, it is irrational to display all the information on a single page. Therefore, the solution is to use the paging technology.
1, rs. RecordCount
Obviously, RecordCount is used to display the total number of records in a database table, and you can also vividly describe the total number of rows in the table. It is often used in PagingN Articles in totalAnd so on.
2, rs. PageSize
Rs. PageSize indicates the size of a page, which indicates the number of records displayed on an ASP page. The value is defined by yourself, for example, often seenShow N Articles per page.
3, rs. AbsolutePage and rs. pagecount
When it comes to paging, we must not mention rs. AbsolutePage. The main function of the AbsolutePage attribute of the record set is to determinePage number. The value is based on the rs. PageSize value specified. The information value of rs. pagecount is the result of the division of rs. RecordCount and rs. PageSize. For example, rs. recordCount contains 20 records, and the number of records per page is rs. if PageSize is set to 5, the page number rs. pagecount is 20/5 = 4 times, while rs. absolutePage can only be 1st pages, 2nd pages ...... Page 1.
Now, let's get a specific program for debugging. ContinueShowit. aspMake the following changes:
| <! -- # Include file = "conn. asp" -->
<%
Set rs = Server. CreateObject ("ADODB. Recordset ")
SQL = "Select * from cnarticle order by cn_id desc"
Rs. Open SQL, conn, 1, 1
%>
<%
Page = request. querystring ("page") 'page value is the accepted value.
Rs. PageSize = 2' number of records displayed per page
Rs. AbsolutePage = page': the current Page is equal to the number of pages received
%>
<%
For I = 1 to rs. PageSize 'uses the for next loop to read records of the current page in sequence
If rs. EOF then
Exit
End if
Response. write ("<br> content:" & rs ("cn_content "))
Rs. MoveNext
Next %>
<%
Rs. close
Set rs = Nothing
Conn. close
Set conn = nothing
%> |
HERE, the premise for debugging is that there are more than four records in the database, so that the test effect is obvious. The test method isShowit. aspAdd? Page = 1Or? Page = 2Etc.
In fact, in the end, displaying the database content is
<%
For I = 1 to rs. PageSize
If rs. EOF then
Exit
End if
Response. write ("<br> content:" & rs ("cn_content "))
Rs. MoveNext
Next %>
|
But imagine: this programShouldOnly two messages can be displayed ). But why?? Page = 1And? Page = 2Will different results be displayed ?...... That is definitely the role of rs. AbsolutePage. I believe that the overall paging architecture will be a bit eye-catching.
| <! -- # Include file = "conn. asp" -->
<%
Set rs = Server. CreateObject ("ADODB. Recordset ")
SQL = "Select * from cnarticle"
Rs. Open SQL, conn, 1, 1
%>
<% Filepath = request. servervariables ("path_info") %>
<%
Page = request. querystring ("page") 'page value is the accepted value.
Rs. PageSize = 2' number of records displayed per page
If Not IsEmpty (page) then' if the page has been initialized...
If Not IsNumeric (page) then' determines whether the page value is a number.
Page = 1
Else
Page = cint (page) 'receives the page and assigns it to the page variable as a number.
End if
If Page> rs. PageCount then', if the number of pages received exceeds the total number of pages
Rs. AbsolutePage = rs. PageCount
Elseif Page <= 0 then' if the page is smaller than or equal to 0
Rs. AbsolutePage = 1' set the current display page to be equal to the first page
Else
Rs. AbsolutePage = Page. If it is greater than zero, the current Page is displayed equal to the number of pages received.
End if
Else
Rs. AbsolutePage = 1
End if
Page = rs. AbsolutePage %>
<%
For I = 1 to rs. PageSize 'uses the for next loop to read records of the current page in sequence
If rs. EOF then
Exit
End if
Response. write ("the title of the article is:" & rs ("cn_title "))
Response. write ("<br> author:" & rs ("cn_author "))
Response. write ("<br> when the article was added:" & rs ("cn_time "))
Response. write ("<br> content:" & rs ("cn_content "))
Response. write ("Rs. MoveNext
Next
%>
<Form action = "<% = filepath %>" method = "get">
<! -- First ensure that the total number of pages is not 1 or 0 -->
<% If rs. pagecount <> 1 and rs. pagecount <> 0 then %>
<! -- If the current page number is greater than 1, the connection between the home page and the previous page should be displayed at any time -->
<% If page> 1 then %>
[<A Href = "<% = filepath %>? Page = <%= 1%> "> homepage </a>]
[<A Href = "<% = filepath %>? Page = <% = page-1%> "> previous Page </a>]
<! -- If the current page number is greater than 1 and less than the total page number, the link between the last page and the next page is displayed. -->
<% If page <rs. pagecount then %>
[<A Href = "<% = filepath %>? Page = <% = page + 1%> "> next Page </a>]
[<A Href = "<% = filepath %>? Page = <% = rs. PageCount %> "> last Page </a>]
<! -- If the current page number is greater than 1 and is still greater than or equal to the total page number, the link between the last page and the next page is not displayed. -->
<% Else %>
[Next Page] [Last Page]
<% End if %>
<! -- Otherwise, if the current page number is not greater than 1, only connections between the last page and the next page are displayed -->
<% Else %>
[Homepage] [Previous Page]
[<A Href = "<% = filepath %>? Page = <% = page + 1%> "> next Page </a>]
[<A Href = "<% = filepath %>? Page = <% = rs. PageCount %> "> last Page </a>]
<% End if %>
<! -- In the end, if the total number of pages is 1 and 0, there is no connection. -->
<% Else %>
[Homepage] [Previous Page] [Next Page] [Last Page]
<% End if %>
[Page times: <font color = red> <B> <% = page %> </B> </font>/<% = rs. PageCount %>]
[Total <% = rs. RecordCount %> <font color = red> <B> <% = rs. PageSize %> </B> </font> articles/pages]
Go to the <input name = "page" size = 5 value = "<% = page %>"> page
<Input type = "submit" value = "Enter">
</Form>
<%
Rs. close
Set rs = Nothing
Conn. close
Set conn = Nothing
%> |
See:
Http://www.cnbruce.com/database/
It is really difficult to understand the long paging code, and it is also difficult to modify the reference of the platform. Finally, we can make a function, which is very convenient to call next time.
<%
Function pagination (pagecount, pagesize, page, resultcount)
Dim query, a, x, temp
Action = "http: //" & Request. ServerVariables ("HTTP_HOST") & Request. ServerVariables ("SCRIPT_NAME ")
Query = Split (Request. ServerVariables ("QUERY_STRING "),"&")
For Each x In query
A = Split (x, "= ")
If StrComp (a (0), "page", vbTextCompare) <> 0 Then
Temp = temp & a (0) & "=" & a (1 )&"&"
End If
Next
Response. Write ("<form method = get onsubmit =" "document. location = '" & action &"? "& Temp &" Page = '+ this. page. value; return false; ""> ")
If page <= 1 then
Response. Write ("[homepage] [Previous Page]")
Else
Response. Write ("[<a href =" & action &"? "& Temp &" Page = 1> homepage </a>] ")
Response. Write ("[<a href =" & action &"? "& Temp &" Page = "& (Page-1) &"> previous Page </a>] ")
End if
If page> = pagecount then
Response. Write ("[Next Page] [last page]")
Else
Response. Write ("[<a href =" & action &"? "& Temp &" Page = "& (Page + 1) &"> next Page </a>] ")
Response. Write ("[<a href =" & action &"? "& Temp &" Page = "& pagecount &"> last Page </a>] ")
End if
Response. Write ("[page times: <font color = red>" & page & "</font>/" & pageCount)
Response. Write ("] [total" & resultcount & "entries <font color = red>" & pagesize & "</font> entries/Page]")
Response. write ("go to" & "<input name = page size = 4 value =" & page & ">" & "page <input type = submit value = go> ")
End function
%> |
To reference, you can:
<% Call pagination (rs. PageCount, rs. pagesize, page, rs. RecordCount) %>