Recommended: What is the difference between ASP and ASP In previous articles we recognized that ASP is part of a complete operating system. But why is ASP different from previous versions of ASP? What is the difference between them? If you're just running some pages or applications, you probably won't notice it at all
When learning ASP, the essential thing is to use four major operations: adding, deleting, modifying and checking. The most troublesome thing is to output the data in the database to the client. When there is very little data, for example, there are a few pieces in a database, so you can output it directly. But if there is a lot of data, the query cannot be completed by relying solely on SQL optimization.
So, how can we optimize the query results? Maybe we will think of paging. Yes, ASP built-in components provide us with a RecordSet object. We can use several properties of this object to easily get the results we want.
Most of the friends who have studied ASP can write paging codes, so okay, we will write this way.
Suppose we are connected to the database.
<!--#include file=conn.asp --> 'Include database connection string
rs.pagesize=10 'Set 10 records displayed per page
page=cint(request(page)) 'Use queryscring to get the current predecessor
if page<1 then page=1 'The first page is displayed when the number of pages is less than 1
if page>rs.pagecount then page=rs.pagecount 'Show the last page when the number of pages is greater than the last page
myself=request.serververables(path_info) 'get the relative path of the current page
if page>1 then rs.absolutepage=page 'If the number of pages is greater than 1, the absolute number of pages will be displayed
'Cycle output page count
for i=1 to rs.pagecount
if rs.eof then exit for 'Record exits the loop after the last one
if i=page then
response.write | &i& |
else
response.write | <a href=&myself&/page=&i&>&i&</a> |
end if
end for
'Cycle output record number
for i=1 to rs.pagesize
if rs.eof then exit for
response.write rs(id)
response.write rs(user)
response.write rs(pwd)
rs.movenext
end for
'Close the database and connect
rs.close
conn.close
set conn=nothing
set rs=nothing
However, this does not achieve optimal optimization. If we enter this after page: page=adsf . We will see the error result because the cint function cannot convert strings to integers. Sometimes you see no errors, because you wrote a statement like this when you connected to the database: on error resume next . It means that when a program error occurs, it will not affect other statements to continue execution. If we delete this code, it will be an error. So, we consider how to avoid mistakes? We can put a statement like this:
page=cint(request(page))
Write this way:
page=strim(request(page))
if IsNumeric(page) then
page=cint(page)
else
page=1
end if
In this way, when we enter a number, whether it is a decimal or other numbers, it will be converted into an integer. When we enter a non-digit, the page is equal to 1, which ensures that the program will not make any mistakes!
Share: Simple WEB development specifications 1. Page design part 1.img control alt: All display images must have text descriptions that can briefly describe the content of the image. 2. Input control maxlength: All INPUT controls need to formulate maxlength attribute, and the default value is the length of the corresponding field in the database.