根据字数对文章进行页内分页 [转自:711网络工作室 http://www.tc711.com]
<% function word_pagination(table,content,wordcount) dim wordPage,action,ami_wordCount,ami_wordSum,ami_wordMod,ami_pageCount,query, ami, ly, temp wordPage=request.QueryString("wordPage") '获得wordPage action = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME") '获得网页地址 query = Split(Request.ServerVariables("QUERY_STRING"), "&") '获得参数,并分解参数 For Each ly In query ami = Split(ly, "=")'对参数进行分析 If StrComp(ami(0), "wordPage",vbTextCompare) <> 0 Then '若参数排除本函数生成的参数 temp = temp & ami(0) & "=" & ami(1) & "&" '生成参数列表(ami=1) End If next set rs=server.CreateObject("adodb.recordset") sql="select * from "&table&" " 'table 表明 rs.open sql,conn,1,1 ami_content=rs(""&content&"") 'content 进行分页内容的字段名 ami_wordCount=wordCount '每页字数 ami_wordSum=len(ami_content) '计算总字数 ami_wordMod=ami_wordSum mod ami_wordCount '计算最后一页字数 ami_pageCount=int(ami_wordSum/ami_wordCount)'计算页数,总页数=ami_pagecount+1 if wordPage="all" then '单页显示值 wordPage=0 end if if isEmpty(wordPage)=true then '分析如wordPage无参数传来,wordpage则为首页 wordPage=1 else wordPage=int(wordPage) '否则等于参数值,并int end if if wordPage=0 then '判断参数的几种类型,并根据参数的类型进行分页 ami_content=ami_content elseif wordPage<ami_pageCount+1 and wordPage>0 then ami_content=mid(ami_content,ami_wordCount*(wordPage-1)+1,ami_wordCount) elseif wordPage=ami_pageCount+1 then ami_content=mid(ami_content,ami_wordCount*ami_pageCount+1,ami_wordMod) elseif wordPage>ami_pageCount+1 and wordPage<0 then ami_content="非法参数,请返回" end if response.Write ami_content response.Write "<br>" for i=1 to ami_pageCount+1 '页数展示 response.Write "[<a href="&action&"?"&temp&"wordPage="&i&">"&i&"</a>]" next response.Write "[<a href="&action&"?"&temp&"wordPage=all>单页显示</a>]" rs.close set rs=nothing end function %> [转自:711网络工作室 http://www.tc711.com]
调用函数的代码是
<%call word_pagination("amily","content",600)%>
大家也注意到了咯 `````
function word_pagination(table,content,wordcount) table 为表明 content 为字段名 (添加的时候 注意加引号咯) wordcount 为字数
嘿嘿 今天先到这里把 程序还有一些不好的地方 比如分页的时候 会直接断句 这个下次 再来咯
|