What is the pagination display when Ado Access Database? If you have used the electronic bulletin board on many websites, then you should know that the electronic bulletin program will not increase all the posts in one page in order to increase the read speed of the page, but will not list all the posts in one page, but will It is divided into multi-page display, and each page shows a number of posts, such as 20. Do you want to know how to implement pagination display? Please see this article!
The "Dynastist Website Design Eighth War --ASP" The article has spent more than half of the year since the first phase, and believes in learning, practicing, and practical, everyone through learning, practice, re-practice, everyone It has been able to skilled the built-in object of ASP, and the ActiveX component will write some basic ASP applications. From the letter from my friends, I can feel obvious, everyone's ASP skills are constantly improving. Recently, many friends have to believe I hope that I have written some examples in reality. Therefore, from this issue, I decided to turn the positioning of "Dynamic Website Design Eighteen Wushu --asp" from the introduction and learning ASP basic knowledge to the actual operation of ASP. At the request of your friends, I will give you a question about "How to Display" when the ADO Acquisition Database is displayed.
What is the pagination display when Ado Access Database? If you have used the electronic bulletin board on many websites, then you should know that the electronic bulletin program will not increase all the posts in one page in order to increase the read speed of the page, but will not list all the posts in one page, but will It is divided into multi-page display, and each page shows a number of posts, such as 20. This is the paging display of the database query. If you still don't understand, go see Yahoo and other search engines, you will understand.
So how do you want to display the database's query result paging? In fact, there are many ways, but there are two main types:
First, read all the records in the database in accordance with the query condition in the database, read in the Recordset, store in memory, and then the attributes provided by the ADO Recordset objects: PageSize, PageCount Page number) and ABSOLUTEPAGE (absolute page) to manage paging processing.
Second, according to the customer's instruction, each time the specified number of records read from the records in accordance with the query condition, and display it.
The main difference between the two is that the former is one-time to read all records into memory and then determine the effect of judgment analysis to achieve the paging display according to the instruction, and the latter is first based on the instructions and the specified number of query conditions Record read into memory, which directly reaches the features of the paging display.
We can feel clearly that when the number of records in the database reaches tenstle or more, the implementation efficiency of the first method will be significantly lower than the second method, because all the customer query pages will be all Eligible records are stored in server memory, and then processed by paging, if there are more than 100 customer online queries, then the execution efficiency of the ASP application will be affected. However, when the number of records on the server and the number of online people are not many, the two are different in operation efficiency. At this time, the first method is generally used, because the ASP program of the first method is relative The second method should be much more clear.
Here, the author is to analyze how our common ASP BBS programs, to analyze how to implement paging display in the BBS program, because the number of database records of the BBS program we generally use and too much access Therefore, the following program example is the first paging display method using previously described.
The paging display when the ADO access database is actually operated on the record of the Recordset. So we must first learn about the properties and methods of the REORDSET object:
BOF attribute: The current indicator refers to the first pen of Recordset.
EOF attribute: The current indicator refers to the last pen of Recordset. MOVE method: Move the indicator to a record in the Recordset.
AbsolutePage Properties: Setting the location of the current record is where the ABSOLUTEPSITION property: The current indicator is in the Recordset.
PageCount Properties: Displays the Recordset object that includes how much "page".
PageSize Attribute: Displays the number of records displayed in each page of the Recordset object.
RecordCount Properties: Displays the total number of recordset object records.
Let's let us know more about these important properties and methods.
First, Bof and EOF attribute
Usually we write code in the ASP program to verify the BOF and EOF attributes, to learn the location of the RecordSet points to the current indicator, use the BOF and EOF properties, you can know if a RecordSet object contains a record or know if the mobile record line is It has exceeded the range of the Recordset object.
Such as: <% if not rs.eof the ...%>
<% IF not (rs.bof and re)%>
If the current recorded position is before the first row of Recordset objects, the BOF attribute returns True, and then returns FALSE.
If the current recorded position is after the last line record of a Recordset object, the EOF property returns true, and then returns false.
BOF and EOF are false: indicates that the indicator is located in the Recordset.
BOF is true: The current indicator refers to the first record of the Recordset. EOF is True: The current indicator refers to the last record of the Recordset.
Bof and EOF are True: There is no record in the Recordset.
Second, MOVE method
You can use the MOVE method to move the indicator to a record in the Recordset, the syntax is as follows:
Rs.Move NumRecords, Start
Here, "RS" is an object variable, indicating a Recordset object you want to move when the current recording location; "NumRecords" is a positive and negative number, setting the number of movements of the current recording location; "start" is an optional The project used to specify the label that records the start.
All RecordSet objects support MOVE methods. If the NumRecords parameter is greater than zero, the current record position moves in the end of the end; if it is less than zero, the current record position moves in the direction of the beginning; if an empty Recordset object calls the MOVE method, will An error will occur.
MoveFirst method: Move the current recording location to the first record.
MoveLAST method: Move the current record position to the last record.
MoveNext method: Move the current recording location to the next record. MovePRevious method: Move the current record position to the previous record.
Move [N] Method: Move indicator to the nth record, N is calculated from 0.
Third, absolutePage properties
AbsolutePage Properties Setting the current recorded position is the page number number; use the PageSize property to split the RecordSet object into logical pages, the number of records per page is Pagesize (except for the last page may be less than The number of records of Pagesize). Here you must pay attention to not all data providers support this attribute, so be careful when using it.
As with the AbsolutePosition property, the absolutePage property is started at 1, and if the current record is recorded as the RECORDSET, AbsolutePage is 1. The AbsolutePage property can be set to move to a first row record location of a specified page. Fourth, AbsolutePosition Attribute
If you need to determine the location of the current indicator in the Recordset, you can use the AbsolutePosition attribute.
The value of the absolutePosition attribute is the current indicator relative to the first position, and the first AbsolutePosition is 1.
Note that when accessset is accessed, the Recordset cannot appear in the same order each time.
To enable AbsolutePosition, you must first set to use the user-end Cursor (pointer), the ASP code is as follows:
rs2.cursorlocation = 3
Five, PageCount Attributes
Using the PageCount property, determine the data of the Recordset object including how much "page". The "page" here is the collection of data records, the size is equal to the setting of the PageSize property, even if the number of records in the last page is less than the value of PageSize, the last page is also a page of PageCount. It is important to note that all data providers support this attribute.
6. PageSize property
The PageSize property is how to make a pagination display when the ADO access database is determined, and it can determine how much records make up a logically "one page". Set and create a size of a page to allow the use of the AbsolutePage property to move to the first record of other logical pages. The PageSize property is set at any time.
Seven, RecordCount properties
This is also a very common and important attribute. We often use the RecordCount property to find a RecordSet object to include how many records. Such as: <% TOTLE = rs.Recordcount%>
After understanding the above properties and methods of the Recordset object, let's consider how to use them to achieve our purpose of our page display. First, we can set a value for the PageSize property, specify the number of rows that make up the constituting page from the record group; then determine the total number of records through the RecordCount property; then use the total number of records to get the displayed page Total number; Finally, access to the specified page will be completed through the AbsolutePage property. It seems that it is not complicated. Let's take a look at how the program is implemented?
We establish such a simple BBS application, which have the following five fields in its database: "ID", automatic number of each post; "Subject", the subject of each post; "Name", plus user Name; "email", user email address; "postdate", the time of the package. The DSN of the database is "BBS". We will display all the steps of the post paging in a process called "showlist ()", which is convenient to call. The procedure is as follows:
'---- BBS Display Posts Page ----
<% Sub showlist ()%>
<%
PGSZ = 20 'setting switch, specify the number of posts shown in each page, default is 20 sheets
Set conn = server.createObject ("adoDb.connection")
SET RS = Server.createObject ("AdoDb.Recordset") SQL = "SELECT * from Message Order By ID DESC"
'Query all posts and follow the ID of the post
Conn.open "BBS"
RS.Open SQL, CONN, 1, 1
IF = 0 THEN
Response.write "
Else
Rs.pagesize = cint (pgsz) Set the value of the PageSize property
Total = int (rs.recordcount / pgsz * -1) * - 1 'calculates the total number of displayed pages
Pageno = Request ("Pageno")
IF Pageno = "" ""
Pageno = 1
Else
Pageno = PAGENO 1
Pageno = PAGENO-1
END IF
Scrolaction = Request ("scroll")
IF scrollAction = "Previous" 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 "
Position = rs.pagesize * Pageno
Pagebegin = position-rs.pageSize 1
IF position Pagend = position Else Pagend = rs.Recordcount END IF Response.write " database query results: b>" Response.write "(a total of" & RS.Recordcount & "strips eligible information, display" & Pagebegin & "-" & Pagend & ") font> p>" Response.write " Response.write " Rowcount = rs.pageSize Do While Not Rs.eof and Rowcount> 0 IF n = 1 THEN Response.write " Else Response.write " END IF n = 1-n%> If rowcount = 0 and Pageno <> Total Then Response.write ""
topic b> td> User b> td> Email b> td> Publish date b> td> font> "Do While Not (rs is nothing)
"
"
"end if