Recommended: Simple ASP Forum DIY First, use Access to create a new database, set the name to luntan, the name of the data table is information, and create the following fields: text, name, time, and time&rdquo
Recently, I have read some forums about paging ASP programs, but there are still many followers, but there is only code and no detailed explanation. For beginners, this will never be truly mastered. This time I will explain the paging technology in detail so that everyone can understand ASP paging. Okay, let’s have a thorough understanding of the paging program together!
First, let’s see the effect!
Check out the function: The paging program first reads the number of records preset for each page. Here are 5, and the others will be displayed on the next page, and prompts the current number of pages, total number of pages, and total number of records. When the displayed number of pages is the first page, the links on the home page and the previous page are invalid. When the displayed number of pages is the last page, the links on the next page and the last page are invalid.
Next, let’s tell you how to make this pagination effect step by step in the form of examples.
First, the field record_info in the database exists in the info table (there is a database in the instance download). First, link the database and open a record set. The following code:
| The following is the quoted content: <% Set conn=Server.CreateObject(Adodb.Connection) connstr=provider=Microsoft.JET.OLEDB.4.0;Data Source=&Server.MapPath(data.mdb) conn.open connstr Set rs=Server.CreateObject(Adodb.Recordset) sql=Select * from info rs.open sql,conn,1,1 %> |
This code is not explained in detail, I believe that those who are just getting started can do it. For specific explanations, please see the tutorial "Teaching you to use ASP as a message book"
Next, this is a relatively important part of the page, just three lines:
| The following is the quoted content: <% rs.pagesize=5 curpage=Request.QueryString(curpage) rs.absolutepage=curpage %> |
Second sentence:
rs.pagesize=5, what does this mean? It is a built-in property in the Recordset object. Its function is to specify the number of records per page. When set to 5, each 5 records will be put together into one page. For example, there are 21 records in the instance. Then, after using rs.pagesize to paginate, these 21 records will be divided into 5 pages for display.
The third sentence:
This is mainly used for page turn function, passing the URL's post parameter curpage to the curpage variable, and this curpage will get the number of pages the browser wants to reach. (You will understand after running the example)
Sentence 4:
rs.absolutepage, which is also a built-in property, means to specify the value of the curpage variable as the current page.
Now start to let the record loop display:
| The following is the quoted content: <% for i= 1 to rs.pagesize if rs.eof then exit for end if %> <%=rs(record_info)%><br> <% rs.movenext next %> |
Second sentence:
Use a for loop to display the number of records specified in the rs.pagesize property per page.
The third, fourth and fifth sentences:
This sentence means that when the last page does not reach the specified record, it will exit the loop to avoid errors.
Sentence 7:
The record_info field bound to be retrieved from the database is called the records in this field to be displayed loop.
Sentence Ninth:
Use the rs.movenext method to move the rs record set down by one record.
Sentence 10:
for loop statement.
In addition, you can use <%=curpage%> to read out the current page, use <%=rs.pagecount%> to read out the total number of pages, and use <%=rs.recordcount%> to read out the total number of records. For example: The current <%=curpage%> page has a total of <%=rs.pagecount%> pages, a total of: <%=rs.recordcount%> records.
In terms of displaying home page, previous page, next page, and last page, the if...else... statement is used, which is easier to understand.
| The following is the quoted content: <%if curpage=1 then%> front page <%else%> <a href=?curpage=1>Home Page</a> <%end if%> <%if curpage=1 then%> Previous page <%else%> <a href=?curpage=<%=curpage-1%>>Previous page</a> <%end if%> <%if rs.pagecount<curpage 1 then%> Next page <%else%> <a href=?curpage=<%=curpage 1%>>Next Page</a> <%end if%> <%if rs.pagecount<curpage 1 then%> Last page <%else%> <a href=?curpage=<%=rs.pagecount%>>Last Page</a> <%end if%> |
Understand:
front page:
This is determined when using whether the current page is the first page. If the current page is the first page (that is, the home page), then the word "home page" is displayed, and there is no link. Otherwise, a link to jump to the home page is provided.
Previous page:
When the current is the first page, the link is invalid. In turn, the link is to the current previous page. Use: <%=curpage-1%> here, which is to subtract 1 from the current number of pages to get the previous page.
Next page:
Here we need to use the rs.pagecount property to compare. If the total number of pages is smaller than the value of the current number of pages plus 1, it means that this is the next page and the link will be invalid, otherwise the link will be linked to the next page.
Last page:
Like the function of the next page, it is determined that the link is invalid when the last page is the same. Otherwise, the current page is specified as rs.pagecount (total number of pages).
This tutorial ends here. After explanation, you should have a deeper understanding of ASP's pagination technology, right? If you have any questions, you can contact me by leaving a message on the blog.
Share: Web Video Player Program Code General Code When making a program for the customer, I suddenly encountered a problem, that is, when the user of the product page submitted a video playback file, how to play the correct video format according to the submitted URL... I was depressed for a while, and thought about the idea, and then I started to do it... The idea is to get the file type first,