ASP数字分页函数
时间:2011-04-09 来源:moretop
<!--#include file="sysconn.asp"-->
<%
if err then
err.clear
set err = nothing
response.write ("数据库链接出错")
response.end
end if
sql = "select * from lines"
set rs = server.createobject("adodb.recordset")
rs.open sql,conn,1,1
rs.pagesize = 2 '每页显示的几条数据
if request("Page")<>"" then
page = int(request("page"))
if page<1 then page = 1
if page>rs.pagecount then page = rs.pagecount
else
page = 1
end if
rs.absolutepage = page '设置当前页
for i = 0 to rs.pagesize -1
if rs.eof and rs.bof then exit for '显示数据
response.write(rs("L_title")&"<br>")
rs.movenext
next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
call fenye(page,rs.pagecount,7,"page") '调用函数
'定义函数 page 为当前点击页,maxcount 为记录集总数,a 为显示条目数,p为get变量
'此定义函数对照上面所注释的 就很好理解了...
'不明白的 [email protected] 联系我
function fenye(page,maxcount,a,p)
response.write "<a href ='?"&p&"=1'>首页</a> "
response.write "<a href = ?"&p&"="&page-1&">上一页</a> "
if page>a-1 and maxcount >a then
if (page+int((a-1)/2))>maxcount then
pagenow = maxcount - a+1
else
pagenow = page - int((a-1)/2)
end if
for i = 1 to a
response.write "<a href=?"&p&"="&pagenow&">"&pagenow&"</a> "
pagenow = pagenow + 1
next
else
if maxcount < a then
for i = 1 to maxcount
response.write "<a href=?"&p&"="&i&">"&i&"</a> "
next
else
for i = 1 to a
response.write "<a href=?"&p&"="&i&">"&i&"</a> "
next
end if
end if
response.write "<a href = ?"&p&"="&page+1&">下一页</a> "
response.write "<a href = ?"&p&"="&maxcount&">尾页</a>"
end function
%>