ASP 通用文章分页函数(非记录集分页), 返回多个结果, 字典实现 By shawl.qiu

ASP 通用文章分页函数(非记录集分页), 返回多个结果, 字典实现 By shawl.qiu


说明: 
本函数为文章分页, 非记录集分页
本函数实现将文章分页显示, 并以指定长度显示每一分页
本函数实现不需指定 URL, 自动更替 URL
本函数实现返回多个结果, 为: 分页链接-文章统计信息-文章内容, 由字典实现
如果分页大小大于文章总大小, 分页链接将为空.

显示如:
第1页 第2页 第3页 第4页 第5页 
50,000字/页 1/5页 共235,289字
正文...

注: 显示内容的三个元素可自由变更位置.

附注: 
如果您是在查找 记录集分页函数, 鄙人以前也写过一个, 名为 "ASP VBScript 分页函数 by Stabx, 第三版".
链接:    http://blog.csdn.net/btbtd/archive/2006/05/31/765595.aspx

shawl.qiu
2006-09-04
  http://blog.csdn.net/btbtd

主内容: 分页函数及调用代码
  1. linenum
  2. <% 
  3.     dim rs, dic
  4.     set rs=createObject("adodb.recordset")
  5.         rs.open "select * from ctat where aid=15783",conn
  6.         'rs.open "select * from ctat where aid=12850",conn
  7.  
  8.         set dic=fAtPgnt(rs("content"),50000,request.queryString("apid"))
  9.             response.write dic("pgnt")&"<br/>"
  10.             response.write dic("info")&"<br/>"
  11.             response.write dic("cnt")&"<br/>"
  12.         set dic=nothing
  13.         rs.close
  14.     set rs=nothing
  15.  
  16.     function fAtPgnt(aStr,pSize,rId)
  17.     ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  18.     'ASP 通用文章分页函数(非记录集分页), 返回多个结果, 字典实现 By shawl.qiu
  19.     ' http://blog.csdn.net/btbtd
  20.     '2006-09-04
  21.     '''''''''''''''''''''''''''
  22.     '输入参数说明:
  23.     'aStr 为要分页的字符串
  24.     'pSize 为每页大小数字
  25.     'rId 为 URL 参数 ID, 默认为 apid, 由函数里的 rName 变量定义
  26.     '''''''''''''''''''''''''''
  27.     '输出参数说明:
  28.     'obj("pgnt") 为文章翻页链接
  29.     'obj("info") 为文章统计信息
  30.     'obj("cnt") 为文章内容
  31.     '''''''''''''''''''''''''''
  32.     'sample call:
  33.     '''''''''''''
  34.     '    dim rs, dic
  35.     '    set rs=createObject("adodb.recordset")
  36.     '        rs.open "select * from ctat where aid=15783",conn
  37.     '        
  38.     '        set dic=fAtPgnt(rs("content"),50000,request.queryString("apid"))
  39.     '            response.write dic("pgnt")&"<br/>"
  40.     '            response.write dic("info")&"<br/>"
  41.     '            response.write dic("cnt")&"<br/>"
  42.     '        set dic=nothing
  43.     '        
  44.     '        rs.close
  45.     '    set rs=nothing
  46.     ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  47.         if isNumeric(pSize)=false or len(aStr)=0 then exit function
  48.         if isNull(rId) or rId="" or isNumeric(rId)=false then rId=1 '如果分页查询ID为空则 ID为 1
  49.         
  50.         dim aStrLen '取文章总长度的变量
  51.             aStrLen=len(aStr)
  52.         
  53.         '智能URL字符串替换
  54.         dim rqs, url, rName
  55.             rqs=request.ServerVariables("QUERY_STRING")
  56.             rName="apid"
  57.         if rqs="" then
  58.             url="?"&rName&"="
  59.         elseif instr(rqs,rName)<>0 then    
  60.             url="?"&replace(rqs,rName&"="&rId,"")&rName&"=" 
  61.         else
  62.             url="?"&replace(rqs,"&"&rName&"="&rId,"")&"&"&rName&"="
  63.         end if
  64.         
  65.         dim tPg '定义总页数变量
  66.             tPg=int(aStrLen/-pSize)*-1
  67.             
  68.         if rId<1 then rId=1 '如果分页查询ID小于1, 则为1
  69.         if cLng(rId)>cLng(tPg) then rId=tPg '如果分页查询ID大于总页数, 则为总页数
  70.             
  71.         dim cPg '定义取当前页字符起始位置变量
  72.         if rId=1 then cPg=1 else cPg=pSize*(rId-1)+1 '读取文章的起始位置
  73.  
  74.         dim dic '定义字典变量
  75.         set dic = createObject("scripting.dictionary")
  76.             if aStrLen<=pSize then '如果分页大小大于正文大小时, 执行以下操作
  77.                 dic.add "pgnt", "" '增加页面链接到字典
  78.                     
  79.                 '增加统计信息到字典
  80.                 dic.add "info", formatNumber(pSize,0)&"字/页 "&rid&"/"&tPg&"页 共"&_
  81.                 formatNumber(aStrLen,0)&"字"
  82.                 
  83.                 dic.add "cnt", mid(aStr,1) '增加内容到字典
  84.                 set fAtPgnt=dic
  85.                 set dic=nothing
  86.                 exit function
  87.             end if
  88.         
  89.             dim i, temp, temp1
  90.             for i=1 to tPg
  91.                 '如果当前查询ID=i, 则加入高亮CSS类
  92.                 if strComp(rId,i,1)=0 then temp1=" class=""hl"""
  93.                 temp=temp&"<a href="""&url&i&""""&temp1&">第"&i&"页</a> "
  94.             next 
  95.             
  96.             dic.add "pgnt", temp '增加页面链接到字典
  97.                 
  98.             '增加统计信息到字典
  99.             dic.add "info", formatNumber(pSize,0)&"字/页 "&rId&"/"&tPg&"页 共"&_
  100.             formatNumber(aStrLen,0)&"字"
  101.             
  102.             dic.add "cnt", mid(aStr,cPg,pSize) '增加文章内容到字典
  103.         set fAtPgnt=dic
  104.         set dic=nothing
  105.     end function 'shawl.qiu code'
  106. %>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值