2006-4-21 ASP 分页操作, 改良版 by Stabx
效果:
首页 上十 上一 11 12 13 14 15 16 17 18 19 20 下一 下十 尾页 转到___
11/20页 963篇
主文件: dateview.asp , 查询参数 yearview=, 分页参数 pageview=
包含文件: abbr.asp
dateview.asp?yearview=2004&pageivew=1
---/-------------------------------------------------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="include/abbr.asp" -->
<script language="JavaScript" type="text/JavaScript">
<!--// 页面跳转脚本
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<% '查询年份分页 dateview.asp?yearview=2004&pageivew=1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' subject : ASP 分页操作, 改良版 by Stabx
'
' author : Stabx<shawl.qiu@gmail.com>
'
' blog : http://blog.csdn.net/btbtd \ http://btbtd.exblog.jp/
'
' blog name : Phoenix.GI - P.GI
'
' date : 2006-4-21
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' rsn.PageCount / 总页数
' pageview / 当前页数
Dim I '定义循环变量
Dim RPP 'RPP:指定每页显示的记录数,
Dim pageview '翻页变量
I=1 '从 1 开始
RPP=50 '每页显示 50 条记录
pageview=CInt(Request("pageview")) '读取 URL 页号
Dim rsn '定义链接名
Set rsn = Server.CreateObject("ADODB.Recordset") '建立一个 rsn 数据库查询
rsn.ActiveConnection = MM_conn_STRING 'rsn 链接方式, 这是 DW 的链接字符串
rsn.Source = "select article.*, class.*, nclass.* from article, class, nclass where article.classid=class.classid and article.nclassid=nclass.nclassid and year(dateandtime)="&request.QueryString("yearview")&" order by dateandtime asc"
' rsn 查询语句, SELECT 所有列 FROM 表 WHERE 条件 ORDER BY 条件
rsn.CursorType = 1 '游标属性
rsn.CursorLocation = 2 '游标位置
rsn.LockType = 1 '定义数据库查询模式
rsn.Open() '打开数据库链接
rsn.PageSize=RPP '定义每页显示记录数
If pageview<=0 Then pageview=1 '如果 pageview 小于或等于0, 返回值1
If pageview>rsn.PageCount Then pageview=rsn.PageCount ' 如果 pageview 大于分页总数, 返回分页末页值
rsn.AbsolutePage=pageview '定义当前页码
Sub ShowPageInfo(tPageCount,cPageNo) '定义子例程 ShowPageInfo, 显示页数和总页
Response.Write cPageNo&"/"&tPageCount&"页" '显示当前页和总页数
End Sub
Sub ShowPageNavi(tPageCount,cPageNo) ' 定义子例程 ShowPageNavi, 显示分页号
If cPageNo<1 Then cPageNo=1 '如果页数小于 1, 默认为 1; 当前页, cPageNo = Current Page NO.
If tPageCount<1 Then tPageCount=1
If cPageNo>tPageCount Then cPageNo=tPageCount
Dim NaviLength
NaviLength=10 ' 显示数字链接数
Dim I,StartPage,EndPage ' 定义当前页, 开始页, 结束页
StartPage=(cPageNo\NaviLength)*NaviLength+1 '为开始页赋值
if pageview=1 then '判断是否首页, 如果是首页不添加链接,反之添加.
Response.Write "<font color=""#CCCCCC"">首页</font> " '显示没有添加链接热点的"首页"
Else
Response.Write "<a href="&dyv_&rqsyv_&dyvpv_&"1>首页</a> " '首页链接
End If
If (cPageNo Mod NaviLength)=0 Then StartPage=StartPage-NaviLength
EndPage=StartPage+NaviLength-1
If EndPage>tPageCount Then EndPage=tPageCount
If StartPage>1 Then '向后移动一分页, 十页为一分页, 并且以 1, 11, 21... 为每页的开始篇数
Response.Write "<a href="&dyv_&rqsyv_&dyvpv_&(cPageNo-(cPageNo mod 10)-NaviLength+1)&">"&previous10_&"</a> "
Else
Response.Write "<font color=""#CCCCCC"">"&previous10_&"</font> "
End If
If pageview <> 1 and pageview <>0 Then '后移一页
Response.Write "<a href="&dyv_&rqsyv_&dyvpv_&(pageview-1)&">"&previous1_&"</a> "
Else
Response.Write "<font color=""#CCCCCC"">"&previous1_&"</font> "
End If
For I=StartPage To EndPage
If I=cPageNo Then
Response.Write "<b>"&I&"</b>"
Else
Response.Write "<a href="&dyv_&rqsyv_&dyvpv_& I & ">" & I & "</a>"
End If
If I<>tPageCount Then Response.Write " "
Next
If pageview <> rsn.PageCount and pageview <>0 Then '前移一页
Response.Write " <a href="&dyv_&rqsyv_&dyvpv_&(pageview+1)&">"&next1_&"</a> "
Else
Response.Write "<font color=""#CCCCCC"">"&next1_&"</font> "
End If
If EndPage<tPageCount Then '向前移动一分页, 十页为一分页, 并且以 1, 11, 21 为每页的开始篇数
Response.Write " <a href="&dyv_&rqsyv_&dyvpv_&(cPageNo-(cPageNo mod 10)+NaviLength+1)&">"&next10_&"</a> "
Else
Response.Write " <font color=#CCCCCC>"&next10_&"</font> "
End If
if rsn.PageCount<>pageview then '判断是否尾页
Response.Write "<a href="&dyv_&rqsyv_&dyvpv_&rsn.PageCount&">尾页</a>"
Else
Response.Write "<font color=""#CCCCCC"">尾页</font>"
End If
End Sub
%>
<div CLASS="center">
<form NAME="pageform" ID="pageform">
<% showPageNavi rsn.PageCount,pageview %>
<select NAME="menu1" onChange="MM_jumpMenu('parent',this,0)">
<% for i=1 to rsn.PageCount %>
<option VALUE="<%=dyv_&rqsyv_&dyvpv_&i%>"
<% if pageview=i then%> selected <%end if%>>
第<%=i%>页
</option>
<%next%>
</select>
</form>
<% showPageInfo rsn.PageCount,pageview %> <% Response.Write(rsn.RecordCount) %>篇<br />
</div>
<%
If rsn.EOF OR rsn.BOF Then
Else
For I=1 To rsn.PageCount
%>
<%=(pageview-1)*RPP+I%>
<%=rsn("dateandtime")%> <a href="<%=a1_&rsn("article.classid")&a2_&rsn("article.nclassid")&a3_&rsn("articleid")%>"><%= rsn("title") %></a><p/>
<%
rsn.MoveNext
If rsn.EOF OR rsn.BOF Then Exit For
Next
End If
%>
<div CLASS="center">
<form NAME="pageform" ID="pageform">
<% showPageNavi rsn.PageCount,pageview %>
<select NAME="menu1" onChange="MM_jumpMenu('parent',this,0)">
<% for i=1 to rsn.PageCount %>
<option VALUE="<%=dyv_&rqsyv_&dyvpv_&i%>"
<% if pageview=i then%> selected <%end if%>>
第<%=i%>页
</option>
<%next%>
</select>
</form>
</div>
<% rsn.close
set rsn=nothing %>
---/-------------------------------------------------------------------
abbr.asp
<%
'Site Infomation
sitename_="绿色学院 Green Institute" '站点名字
homepageW_="首页"
siteurl_="http://127.0.0.1:83" '站点域名
home_="<a href="&siteurl_&">"&sitename_&"</a>" _fcksavedurl=""&siteurl_&">"&sitename_&"</a>"" '显示站名并加上首页链接
homepage_="<a href="&siteurl_&">"&homepageW_&"</a>" '显示 "首页" 并加站站点链接
sitepublic_="开站日期: 2006-7-1 " '显示开站日期
siteadmin_="shawl.qiu"
siteadminW_="站长"
siteadminMail_="shawl.qiu@gmail.com" '站长电子邮件
contactSiteAdmin_=siteadminW_&":<a HREF=mailto:"&siteadminMail_&">"&siteadmin_&"</a>" _fcksavedurl="mailto:"&siteadminMail_&">"&siteadmin_&"</a>"" '显示站长名字并加上电子邮件链接
' Number Control
n10_=10 ' 显示文章标题长度
n11_=11 ' 显示文章标题长度
n12_=12 ' 显示文章标题长度
n15_=15 ' 显示文章标题长度
' HTML Tag
b_="<br/>" '调用换行符
p_="<p/>"
sp2_=" "
sp2a_=" -> "
' article about
author_="作者:"
hot_=" 热门"
source_="来源:"
newPost_="<div class='center'>最新发表</div>"
previousA_="上篇"
nextA_="下篇"
previous10_="上十"
next10_="下十"
previous1_="上一"
next1_="下一"
nullPA_="没有上篇"
nullNA_="没有下篇"
view_="查看:"
viewT_="次"
pagelinkW_="页面链接: "
'General word
welcomeShort_="欢迎光临"
siteFoundtime_="开站日期: "
localsite_="本站"
' page index.asp
pColumn_="父类"
sColumn_="子类"
' page class.asp
c1_="class.asp?classid=" 'class 类一级链接
c2_="&nclassid=" 'class 类二级链接
' page article.asp
a1_="article.asp?classid=" 'article 页一级链接
a2_="&nclassid=" 'article 页二级链接
a3_="&articleid=" 'article 页三级链接
text_="正文:"
' page dateview.asp
ddv_="dateview.asp?dayview="
dyv_="dateview.asp?yearview="
dyvpv_="&pageview="
dmv_="dateview.asp?monthview="
dwkv_="dateview.asp?weekview="
dtv_="dateview.asp?todayview="
show_="显示"
today_="今天"
showAll_="所有文章"
showByW_="所属星期"
' error info
errorCidNidAid_="<meta HTTP-EQUIV='refresh' CONTENT='3;URL=index.asp'><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><center>页面错误, 三秒后返回主页</center>"
errorNothing_="<center>没有内容</center>"
errorNJH_="<meta HTTP-EQUIV='refresh' CONTENT='3;URL=index.asp'><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><center>没有内容, 三秒后返回主页</center>"
' query string
rqsyv_=request.QueryString("yearview")
' url
pagelink1_=siteurl_&request.ServerVariables("URL")&"?"&request.ServerVariables("QUERY_STRING")
pagelink_=pagelinkW_&"<a href="&pagelink1_&">"&pagelink1_&"</a>"
%>
---/-------------------------------------------------------------------
/*****************************************************************
* subject :
*
* author : Stabx<shawl.qiu@gmail.com>
*
* blog : http://btbtd.exblog.jp/ / http://my.opera.com/btbtd/
*
* blog name : Phoenix.GI - P.GI
*
* date : 2006-4-17
*
\****************************************************************/