📄 分页.asp
字号:
<!--#include file="conn.asp"-->
<html>
<body bgcolor="#FFFFFF" text="#000000">
<table width="60%" border="1" align="center">
<%
dim sql
msg_per_page = 4 '定义每页显示记录条数
sql = "select * from book order by time" '改成你自己的SQL语句
rs.cursorlocation = 3 '使用客户端游标,可以使效率提高
rs.pagesize = msg_per_page '定义分页记录集每页显示记录数
rs.open sql,conn,0,1
if err.number<>0 then '错误处理
response.write "数据库操作失败:" & err.description
err.clear
else
if not (rs.eof and rs.bof) then '检测记录集是否为空
totalrec = RS.RecordCount 'totalrec:总记录条数
if rs.recordcount mod msg_per_page = 0 then
n = rs.recordcount\msg_per_page 'n:总页数 '如果总页数/每页显示记录条数正好为整数
else
n = rs.recordcount\msg_per_page+1 '总页数/每页显示记录条数不为整数,表示有小于每页显示记录条数的数据出现,也应做为一页显示
end if
currentpage = request("page") 'currentpage:当前页
'以下防止在浏缆器中直接输入错误参数
If currentpage <> "" then
currentpage = cint(currentpage)'小数->整数
if currentpage < 1 then '小于1的数
currentpage = 1
end if
if err.number <> 0 then
err.clear
currentpage = 1
end if
else
currentpage = 1
End if
if currentpage*msg_per_page > totalrec and not((currentpage-1)*msg_per_page < totalrec)then '大于总页数
currentPage=1
end if
rs.absolutepage = currentpage '设置指针指向某页开头
rowcount = rs.pagesize '设置每一页的数据记录数
dim i
dim k
%>
<tr align="center" valign="middle">
<td width="50%">e-mail</td>
<td width="50%">name</td>
</tr>
<%do while not rs.eof and rowcount > 0 '用rowcount定义循环次数即每一页的数据记录数%>
<tr align="center" valign="middle">
<td width="25%"><%=rs("e-mail")%></td>
<td width="25%"><%=rs("name")%></td>
</tr>
<%
rowcount=rowcount-1
rs.MoveNext
loop
end if
end if
rs.close
set rs=nothing
%>
</table>
<table border="5" align="center">
<tr><td align="center" valign="middle">
<%call listPages()%>
</td></tr>
</table>
</body>
</html>
<%
sub listPages()
if n <= 1 then exit sub '只有一页
%>
<p><span class=smallFont>>>
<%'第一页时%>
<%if currentpage = 1 then '第一页%>
<font color=darkgray face="arial" >第一页 前一页</font>
<%else%>
<%'第一页至最后页时%>
<font color=black face="arial">
<a href="<%=request.ServerVariables("script_name")%>?page=1">Top</font></a>
<a href="<%=request.ServerVariables("script_name")%>?page=<%=currentpage-1%>"><font color=black face="arial" >前一页</a></font>
<%end if%>
<%'最后页时%>
<%if currentpage = n then%>
<font color=darkgray face="arial" >下一页最后页</font>
<%else%>
<%'第一页至最后页时%>
<font color=black face="arial" >
<a href="<%=request.ServerVariables("script_name")%>?page=<%=currentpage+1%>">下一页</a>
<a href="<%=request.ServerVariables("script_name")%>?page=<%=n%>">最后页</a></font>
<%end if%>
<font color=black face="arial" >
Page:<%=currentpage%>/<%=n%>页<%=msg_per_page%>条/页 Total:<%=totalrec%>条</font></span></p>
<%end sub%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -