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>&nbsp;"
        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>&nbsp;"
        next
    else                                '当记录集大于9时 但当前页小于9时 执行
        for b = 1 to 9
            response.write "<a href=?page="&b&">"&b&"</a>&nbsp;"
        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>&nbsp;"
        pagenow = pagenow + 1
    next
else
    if maxcount < a then
    for i = 1 to maxcount
        response.write "<a href=?"&p&"="&i&">"&i&"</a>&nbsp;"
    next
    else
    for i = 1 to a
        response.write "<a href=?"&p&"="&i&">"&i&"</a>&nbsp;"
    next
    end if
end if
response.write "<a href = ?"&p&"="&page+1&">下一页</a> "
response.write "<a href = ?"&p&"="&maxcount&">尾页</a>"
end function
-->

标签:google,分页
0
投稿

猜你喜欢

  • Python3 执行系统命令并获取实时回显功能

    2023-12-06 13:23:10
  • tensorflow自定义激活函数实例

    2023-04-18 09:11:51
  • 使用Python画了一棵圣诞树的实例代码

    2022-06-18 23:55:04
  • 使用watch监听对象里面值的变化

    2024-06-07 15:22:10
  • python实现修改固定模式的字符串内容操作示例

    2023-05-13 21:44:04
  • 详解如何利用docker快速构建MySQL主从复制环境

    2024-01-25 08:25:33
  • python中注释用法简单示例

    2022-10-24 05:04:09
  • C#调用Python模块的方法

    2021-04-13 15:29:10
  • Python DataFrame 设置输出不显示index(索引)值的方法

    2022-01-13 20:02:38
  • XMLHTTP自动判断远程网页字符编码

    2007-12-28 13:41:00
  • Vue 列表渲染 key的原理和作用详解

    2024-05-03 15:11:21
  • 详解用Node.js实现Restful风格webservice

    2024-05-13 09:35:20
  • 解决vue3打包过后空白页面的情况

    2024-05-09 10:43:00
  • Python实现word2Vec model过程解析

    2023-10-07 14:22:10
  • 深入了解Python中Lambda函数的用法

    2023-02-03 10:09:01
  • Python 实现简单的电话本功能

    2021-11-16 09:47:58
  • python爬虫框架scrapy代理中间件掌握学习教程

    2021-03-22 15:34:54
  • python 如何查看pytorch版本

    2021-02-05 05:38:59
  • SQL 查询性能优化 解决书签查找

    2024-01-28 08:33:53
  • Mysql数据库手动及定时备份步骤

    2024-01-27 10:43:15
  • asp之家 网络编程 m.aspxhome.com