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! So how do you want to display the database's query result paging? In fact, there are many ways.
However, there are two: 1. 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 through the ADO Recordset objects that specifically support the profile processing: PageSize Page size), PageCount, 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 the properties and methods of the REORDSET object: BOF properties: 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 us let us know more about these important properties and methods 1. BOF and EOF properties typically write code in the ASP program to verify the BOF and EOF properties, so that the current indicator points to the Recordset point, use BOF and EOF Attributes, you can know if a RecordSet object contains a record or knows if the mobile recording line has exceeded the RECORDSET object. Such as: <% IF not xif (rs.bof and rs.eof)%> If the current record is in front of a RECORDSET object, the BOF attribute returns TRUE, it 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 methods You can use the MOVE method to move the indicator to a record in the Recordset, the syntax is as follows:
Rs.Move NumRecords, "RS" here "rs" is an object variable, indicating a Recordset object you want to move when the current record location; "NumRecords" is a positive and negative number, setting the number of movements of the current record location; " START "is an optional item that specifies the label that records the starting. 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, the absolutepage property The ABSOLUTEPAGE property Sets the current recorded position is the page number number; use the PageSize property to split the RecordSet object into logical pages, each page records as Pagesize (except the last page There will 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 of the Recordset is currently recorded, AbsolutePage is 1. The AbsolutePage property can be set to move to a first row record location of a specified page. 4. AbsolutePosition Attribute If you need to determine the current indicator in the Recordset, you can use the AbsolutePosition property. 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 5, the pageCount property uses the PageCount property to determine the Recordset object includes how much "page" data. 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 Attributes The PageSize property is how to make a pagination display when the ADO is used, using it to 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 are 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: <% = rs.recordcount%> After learning the above properties and methods of the Recordset object, let's consider how to use them to reach our pagination 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; Finally, you can complete access to the specified page through the ABSOLUTEPAGE attribute. 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 Post Page ---- <% Sub showlist ()%> <% pgsz = 20' setting switch, specify the number of posts displayed 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" "query all posts "BBS" RS.Open SQL, CONN, 1, 1IF RS.Recordcount = 0 TenResponse.write "
topic b> td> | User b> <
转载请注明原文地址:https://www.9cbs.com/read-104113.html New Post(0)
|