作用: 为了通用性考虑, 本函数主要功能为分页导航, 定义数据库连接和调用数据在调用页操作.
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>"" '显示站名并加上首页链接