asp访google分页代码
时间:2009-07-10 13:06:00
<%
on error resume next
dim conn,sql,rs
set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.oledb.4.0;data source=" & Server.MapPath("data/note.mdb")
%>
<%
'strconn = "driver={Microsoft Access Driver (*.mdb)};dbq="& server.mappath("fenye.mdb")
'set conn = server.createobject("adodb.connection")
'conn.open strconn
if err then
err.clear
set err = nothing
response.write ("数据库链接出错")
response.end
end if
sql = "select * from say Order by time DESC"
set rs = server.createobject("adodb.recordset")
rs.activeconnection = conn
rs.source = sql
rs.cursortype = 1
rs.locktype =1
rs.open
rs.pagesize = 20 '每页显示的几条数据
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("content")&"<br>")
rs.movenext
next
response.write "<a href = 1.asp>首页</a> "
response.write "<a href = 1.asp?page="&page-1&">上一页</a> "
' 重要部分,每次显示 9 个数字分页链接
if page >8 and rs.pagecount > 9 then '判断点击页大于8 并且记录集页数大于9时
if (page + 4)> rs.pagecount then '当点击页加上4 (4 的来历为 8/2) 大于 记录集是
pagenow = rs.pagecount - 8 '首次数字显示页码
else '否则
pagenow = page - 4 '点击页 减 4 (4 的来历为 8/2) 为了让点击页码
'数居中
end if
for b = 1 to 9 '每次显示9 条记录
response.write "<a href=?page="&pagenow&">"&pagenow&"</a> "
pagenow = pagenow+1
next
else
if rs.pagecount<9 then '当记录集小于9时
for b = 1 to rs.pagecount '显示数字分页码
response.write "<a href=?page="&b&">"&b&"</a> "
next
else '当记录集大于9时 但当前页小于9时 执行
for b = 1 to 9
response.write "<a href=?page="&b&">"&b&"</a> "
next
end if
end if
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
response.write "<a href = 1.asp?page="&page+1&">下一页</a> "
response.write "<a href = 1.asp?page="&rs.pagecount&">尾页</a>"
response.write "<br><br>"
%>
<!--''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'根据上面的讲解 我们把他做成一个函数 可重复调用
call fenye(page,rs.pagecount,7,"page") '调用函数
'定义函数 page 为当前点击页,maxcount 为记录集总数,a 为显示条目数,p为get变量
'此定义函数对照上面所注释的 就很好理解了...
'不明白的 slvzs-g@yahoo.com.cn 联系我
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
-->