2006-4-22 ASP VBScript 分页函数 by Stabx, 2006-04-22
2006-4-22 ASP VBScript 分页函数 by Stabx, 2006-04-22
2006-4-22 ASP VBScript 分页函数 by Stabx, 2006-04-22
作用: 为了通用性考虑, 本函数主要功能为分页导航, 定义数据库连接和调用数据在调用页操作.
1.1 函数 fPageCount 内容
1.2 包含文件 abbr.asp, 非必须
2.1 使用函数例1
2.2 使用函数例2
2.3 使用函数例3
注: 例中的脚本为跳转框必须
效果:
-------------------------------------------------------------
首页 上十 上一 1 2 3 4 5 6 7 8 9 10 下一 下十 尾页 转到:___
50篇/页 1/21页 1031篇
-------------------------------------------------------------
1.1 函数 fPageCount 内容
<% 'ASP VBScript 分页函数, by Stabx, 2006-04-22
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 调用文件参数设置
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' RPP=50 '设置每页显示数目
' I=1 '设置循环开始数目
' showNumberLink_=10 '数字导航显示数目
'
' toPage_='?yearview='&request.QueryString('yearview')&'&pageview=' '页面链接
' nonLinkColor_='#CCCCCC' '非热链接颜色
'
' '数据库连接
' Set rs = Server.CreateObject('ADODB.Recordset') '建立一个 rs 数据库查询
' rs.ActiveConnection = MM_conn_STRING '连接字符串, 这是 Dreamweaver 连接字符串
' rs.CursorType = 1 '游标属性
' rs.CursorLocation = 2 '游标位置
' rs.LockType = 1 '定义数据库查询模式
' rs.Open '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 desc',MM_conn_STRING
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 调用函数, 显示分布导航栏
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' call fPageCount(RPP,rs,I,showNumberLink_,toPage_,nonLinkColor_)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 调用文件,显示数据操作
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' if rs.eof or rs.bof then
' else
' for i=1 to rpp
' response.Write rs('title')&p_
' rs.movenext
' if rs.eof or rs.bof then exit for
' next
' end if
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' FOR ... NEXT 语句段编辑显示内容,
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function fPageCount(RPP,rs,I,showNumberLink_,toPage_,nonLinkColor_)
toF_='首页'
toP10_=' 上十'
toP1_=' 上一'
toN1_=' 下一'
toN10_=' 下十'
toL_='尾页'
if not rs.eof or not rs.bof then
pageview=CInt(Request('pageview')) '读取 URL 页号
rs.PageSize=RPP '定义每页显示记录数
If pageview<=0 Then pageview=1 '如果 pageview 小于或等于0, 返回值1
If pageview>rs.PageCount Then pageview=rs.PageCount ' 如果 pageview 大于分页总数, 返回分页末页值
rs.AbsolutePage=pageview '定义当前页码
cPageNo=rs.AbsolutePage
tpagecount=rs.pagecount
response.Write '<form NAME=pageform ID=pageform>'
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=showNumberLink_ ' 显示数字链接数
Dim StartPage,EndPage ' 定义当前页, 开始页, 结束页
StartPage=(cPageNo\NaviLength)*NaviLength+1 '为开始页赋值
if pageview=1 then '判断是否首页, 如果是首页不添加链接,反之添加.
Response.Write '<font color='&nonLinkColor_&'>'&toF_&'</font> '
Else
Response.Write '<a href='&toPage_&'1>'&toF_&'</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='&toPage_&(cPageNo-(cPageNo mod 10)-NaviLength+1)&'>'&toP10_&'</a> '
Else
Response.Write '<font color='&nonLinkColor_&'>'&toP10_&'</font> '
End If
If pageview <> 1 and pageview <>0 Then '后移一页
Response.Write '<a href='&toPage_&(pageview-1)&'>'&toP1_&'</a> '
Else
Response.Write '<font color='&nonLinkColor_&'>'&toP1_&'</font> '
End If
For I=StartPage To EndPage
If I=cPageNo Then
Response.Write '<b>'&I&'</b>'
Else
Response.Write '<a href='&toPage_&I&'>' &I& '</a>'
End If
If I<>tPageCount Then Response.Write ' '
Next
If pageview <> rs.PageCount and pageview <>0 Then '前移一页
Response.Write ' <a href='&toPage_&(pageview+1)&'>'&toN1_&'</a> '
Else
Response.Write '<font color='&nonLinkColor_&'>'&toN1_&'</font> '
End If
If EndPage<tpagecount Then '向前移动一分页, 十页为一分页, 并且以 1, 11, 21 为每页的开始篇数
Response.Write ' <a href='&toPage_&(cPageNo-(cPageNo mod 10)+NaviLength+1)&'>'&toN10_&'</a> '
Else
Response.Write ' <font color=#CCCCCC>'&toN10_&'</font> '
End If
if rs.PageCount<>pageview then '判断是否尾页
Response.Write '<a href='&toPage_&rs.PageCount&'>'&toL_&'</a>'
Else
Response.Write '<font color='&nonLinkColor_&'>'&toL_&'</font>'
End If
'跳转框
response.Write ' 转到:<select NAME=menu1 onChange=MM_jumpMenu('parent',this,0)>'
for i=1 to tPageCount
response.Write '<option value='&topage_&i
if pageview=i then response.Write ' selected '
response.Write '>第'&i&'页</option>'
next
response.Write '</select>'
'页面信息
response.Write p_&sp2_&RPP&'篇/页'&sp2_&cPageNo&'/'&tPageCount&'页'&sp2_&rs.recordCount&'篇'
response.Write '</form>'
else
end if
end function
%>
1.2 包含文件 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 /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>'
%>
2.1 使用函数例1
<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>
<%
RPP=50 '设置每页显示数目
I=1 '设置循环开始数目
showNumberLink_=10
toPage_='?dayview='&request.QueryString('dayview')&'&pageview='
nonLinkColor_='#CCCCCC'
Set rs = Server.CreateObject('ADODB.Recordset') '建立一个 rs 数据库查询
rs.ActiveConnection = MM_conn_STRING
rs.CursorType = 1 '游标属性
rs.CursorLocation = 2 '游标位置
rs.LockType = 1 '定义数据库查询模式
rs.Open 'select article.*, class.*, nclass.* from article, class, nclass where article.classid=class.classid and article.nclassid=nclass.nclassid and dateandtime=#'&request.QueryString('dayview')&'# order by articleid desc',MM_conn_STRING
%>
<div call fPageCount(RPP,rs,I,showNumberLink_,toPage_,nonLinkColor_) %></div>
<%
if rs.eof or rs.bof then
else
for i=1 to rpp %>
<div href='<%=ddv_&rs('dateandtime')%>'><%=rs('dateandtime')%></a></div> <a href='<%=c1_&rs('article.classid')%>'><%= rs('class') %></a> -> <a href='<%=c1_&rs('article.classid')&c2_&rs('article.nclassid')%>'><%= rs('nclass') %></a> -> <a href='<%=a1_&rs('article.classid')&a2_&rs('article.nclassid')&a3_&rs('articleid')%>' target='_blank'><%= rs('title') %></a><p/>
<%
rs.movenext
if rs.eof or rs.bof then exit for
next
end if%>
<div call fPageCount(RPP,rs,I,showNumberLink_,toPage_,nonLinkColor_) %></div>
<% rs.close
set rs=nothing %>
2.2 使用函数例2
<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>
<%
RPP=50 '设置每页显示数目
I=1 '设置循环开始数目
showNumberLink_=10
toPage_='?yearview='&request.QueryString('yearview')&'&pageview='
nonLinkColor_='#CCCCCC'
Dim rs '定义链接名
Set rs = Server.CreateObject('ADODB.Recordset') '建立一个 rs 数据库查询
rs.ActiveConnection = MM_conn_STRING
rs.CursorType = 1 '游标属性
rs.CursorLocation = 2 '游标位置
rs.LockType = 1 '定义数据库查询模式
rs.Open '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 desc',MM_conn_STRING
%>
<div call fPageCount(RPP,rs,I,showNumberLink_,toPage_,nonLinkColor_) %></div>
<%
if rs.eof or rs.bof then
else
for i=1 to rpp %>
<div href='<%=ddv_&rs('dateandtime')%>'><%=rs('dateandtime')%></a></div> <a href='<%=c1_&rs('article.classid')%>'><%= rs('class') %></a> -> <a href='<%=c1_&rs('article.classid')&c2_&rs('article.nclassid')%>'><%= rs('nclass') %></a> -> <a href='<%=a1_&rs('article.classid')&a2_&rs('article.nclassid')&a3_&rs('articleid')%>' target='_blank'><%= rs('title') %></a><p/>
<%
rs.movenext
if rs.eof or rs.bof then exit for
next
end if%>
<div call fPageCount(RPP,rs,I,showNumberLink_,toPage_,nonLinkColor_) %></div>
<% rs.close
set rs=nothing %>
2.3 使用函数例3
<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>
<%
RPP=50 '设置每页显示数目
I=1 '设置循环开始数目
showNumberLink_=10
toPage_='?monthview='&request.QueryString('monthview')&'&pageview='
nonLinkColor_='#CCCCCC'
Set rs = Server.CreateObject('ADODB.Recordset') '建立一个 rs 数据库查询
rs.ActiveConnection = MM_conn_STRING
rs.CursorType = 1 '游标属性
rs.CursorLocation = 2 '游标位置
rs.LockType = 1 '定义数据库查询模式
rs.Open 'select article.*, class.*, nclass.* from article, class, nclass where article.classid=class.classid and article.nclassid=nclass.nclassid and year(dateandtime)='&year(request.QueryString('monthview'))&' and '&'month(dateandtime)='&month(request.QueryString('monthview'))&' order by dateandtime asc',MM_conn_STRING
%>
<div call fPageCount(RPP,rs,I,showNumberLink_,toPage_,nonLinkColor_) %></div>
<%
if rs.eof or rs.bof then
else
for i=1 to rpp %>
<div href='<%=ddv_&rs('dateandtime')%>'><%=rs('dateandtime')%></a></div> <a href='<%=c1_&rs('article.classid')%>'><%= rs('class') %></a> -> <a href='<%=c1_&rs('article.classid')&c2_&rs('article.nclassid')%>'><%= rs('nclass') %></a> -> <a href='<%=a1_&rs('article.classid')&a2_&rs('article.nclassid')&a3_&rs('articleid')%>' target='_blank'><%= rs('title') %></a><p/>
<%
rs.movenext
if rs.eof or rs.bof then exit for
next
end if%>
<div call fPageCount(RPP,rs,I,showNumberLink_,toPage_,nonLinkColor_) %></div>
<% rs.close
set rs=nothing %>
2006-4-22