We have already talked about the pagination program to you earlier. Here we provide you with one, and analyze it, and you may have new gains.
The code copy is as follows:
<%
'The following program is part of the code of the programming technology article system in my website, focusing on highlighting pagination, so other useless codes are cleared, you can modify them and apply them
onerrorresumenext' prevents users from modifying URLs at will to cause errors
Ifrequest.querystring("page")=""thenpage=1:else:page=cint(request.querystring("page"))''The number of pages to the URL page=?
setlink1=server.createobject("ADODB.Connection")'Connection database
link1.open"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&server.mappath("Database 1.mdb")
setrs=server.createobject("adodb.recordset")
rs.open"select*from Table 1", link1,1,1' These sentences define the cursor of the record set, the number of records stored per page and the current page settings, which is very important.
rs.pagesize=13
rs.AbsolutePage=page
iferr.number<>0then' prevents users from maliciously modifying URLs and database without records errors
"Exception error occurred" response.write
response.end
endif
%>
<basetarget='_blank'><!--Make content pop up in new window-->
<tableborder=1>
<%
fori=0tors.pagesize-1' displays the specific data content. i+(page*13-13)+1 This solution shows the specific number after paging.
ifrs.eofthenexitfor
response.write"<tr><Td>"&i+(page*13-13)+1&":<Ahref='"&rs("connect")&"'>&rs("Author")&"</a></td></tr>"
rs.movenext
next
%>
<tr><Tdalign=right>
<basetarget='_top'><!--Make the paging connection not pop up in the new window. The following is the complete program of the perfect paging program I want to focus on. You can modify it as needed->
<%
pagelen=split(request.ServerVariables("Query_String"),"&")'Get the parameter URL after the URL? number
ifUBound(pagelen)<1then'If the URL is of type xxx.asp?page=1 or xxx.asp, use the standard pagination method
ifpage>1thenresponse.write"<Ahref='a.asp?page=1'>Home</a><ahref='a.asp?page="&page-1&"'>Previous page</a>":else:response.write"Homepage"
ifpage<rs.pagecountthenresponse.write"<ahref='a.asp?page="&page+1&"'>Next page</a><ahref='a.asp?page="&rs.pagecount&"'>Last page</a>":else:response.write"Next page"
fori=1tors.pagecount
ifi=pagethenresponse.writei&"":else:response.write"<Ahref='a.asp?page="&i&"'>"&i&"</a>"