It should be said that if you have learned how to insert records and display records, then a simple and complete article system, news system and message system are no problem now. Then the following question is: As the information content increases in segments, it is not OK to display all information through a page alone. Therefore, the solution is to use paging technology.
1, rs.RecordCount
Obviously, RecordCount is used to display how many records are in the database table, and it can also vividly describe how many rows are in the table. It is often used in pagination to display a total of N articles and other information.
2. rs.PageSize
rs.PageSize is the size of a page, which means that an ASP page can display the number of records. Values are defined by yourself, such as information such as N articles displayed on each page that you often see.
3. rs.AbsolutePage and rs.pagecount
When it comes to pagination, you must not mention rs.AbsolutePage. The main function of the AbsolutePage property of the record set is to determine which page is currently displayed. Its value is based on. If rs.PageSize is specified, then the information value of rs.pagecount is the dividing result of rs.RecordCount and rs.PageSize. For example: the total information record rs.RecordCount has 20 items, and the number of displayed items per page is set to 5 items. Then the number of pages rs.pagecount is 20/5=4 pages, while rs.AbsolutePage can only be page 1, page 2...page 4.
Speaking of now, we will find a specific program to debug. Continue to modify showit.asp as follows:
<!--#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 'Show the current page is equal to the number of pages received %> <% For i = 1 to rs.PageSize 'Use for next loop to read the record of the current page in sequence if rs.EOF then Exit For end if response.write("<br>The content of the article is: "& rs("cn_content")) rs.MoveNext next%> <% rs.close Set rs = Nothing conn.close set conn=nothing %> |
HERE, the premise of your debugging is that the records in the database must be relatively greater than 4, so that the test effect will be obvious; the test method is to add ?page=1 or ?page=2 and other debugging to observe the display effect of the web page after showit.asp.
In fact, after all, displaying the database content is
<% For i = 1 to rs.PageSize if rs.EOF then Exit For end if response.write("<br>The content of the article is: "& rs("cn_content")) rs.MoveNext next%> |
The function is played, but imagine: the program should only display 2 pieces of information (2 pieces of information that remain unchanged). But why does adding ?page=1 and ?page=2 show different results? ...That is definitely the function of rs.AbsolutePage. I understand this clearly, I believe that the overall architecture of the pagination is a bit confusing.