国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > ASP > 正文

asp中"無(wú)限流"分頁(yè)程序代碼

2020-07-27 13:11:40
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
<%
'******************************************************************
'** 本程序名:"無(wú)限流"分頁(yè)程序
'** 作者:Arbiter(AAsx)
'** 版本:Million Level
'**
'** QQ:22222xx
'** Email:Arbiter@21cn.com
'** http://www.imagecity.org/
'******************************************************************
'**
'** 【作者的話】
'**
'** 分頁(yè)程序無(wú)疑是許多網(wǎng)絡(luò)程序功能中一個(gè)比較麻煩的東西,事實(shí)上現(xiàn)在
'** 為止絕大部分人還是在使用傳統(tǒng)的分頁(yè)方法(Rs.PageSize=xx),而了解
'** 數(shù)據(jù)庫(kù)操作的人都知道,這種傳統(tǒng)方式有個(gè)弊端:第一次打開(kāi)頁(yè)面時(shí),
'** 它會(huì)預(yù)讀所有的記錄集,這當(dāng)在數(shù)據(jù)大的時(shí)候,這將是致命的,而且接
'** 下來(lái)的翻頁(yè)速度也會(huì)非常慢,很占用資源。對(duì)于十萬(wàn)數(shù)量級(jí)以上的數(shù)據(jù)
'** 庫(kù)這種傳統(tǒng)分頁(yè)方式已經(jīng)顯得非常無(wú)力,更別說(shuō)百萬(wàn)級(jí)了(根本沒(méi)法操
'** 作)。基于這種原因,促使我做了本程序。
'**
'** 【程序功能】
'**
'** 針對(duì)大型的數(shù)據(jù)庫(kù)進(jìn)行分頁(yè)操作,理想的可操作的數(shù)據(jù)記錄量在200萬(wàn)
'** 以內(nèi)(Max Level版將無(wú)數(shù)量限制,且無(wú)論數(shù)據(jù)庫(kù)多大,翻頁(yè)速度都是
'** 不變),這是Million Level版分頁(yè)程序在賽揚(yáng)1G、內(nèi)存512、win2k環(huán)
'** 境下的測(cè)試數(shù)據(jù):
'**
'** SQLserver 2k + 10萬(wàn)條記錄 + 每頁(yè)顯示20條:
'** 平均翻頁(yè)速度:45ms
'** SQLserver 2k + 100萬(wàn)條記錄 + 每頁(yè)顯示20條:
'** 平均翻頁(yè)速度:350ms
'**
'**
'** 【分頁(yè)原理】
'**
'** 本程序不再使用Rs.PageSize的方式分頁(yè),連接數(shù)據(jù)庫(kù)的游標(biāo)類(lèi)型
'** 也不是使用conn,1,x,而是conn,0,1,這應(yīng)是最快的游標(biāo)類(lèi)型了,不要
'** 以為這樣會(huì)使程序變得復(fù)雜,相反,程序非常簡(jiǎn)單,如果你看不明白,
'** 應(yīng)該是我的編程風(fēng)格你不習(xí)慣,而非程序復(fù)雜。
'** "無(wú)限流"分頁(yè)的中心是:每頁(yè)只讀出需要顯示的記錄,不再象傳統(tǒng)
'** 分頁(yè)程序預(yù)讀全部的數(shù)據(jù),這正在本程序最大的優(yōu)點(diǎn)--占用資源少,同
'** 理速度也得到非常大的提升,特別在數(shù)據(jù)量越大的時(shí)候,它的速度優(yōu)勢(shì)
'** 越明顯(100萬(wàn)記錄才350ms左右)。
'** 當(dāng)程序執(zhí)行后,使用CurcorBegin和CurcorEnd記錄顯示的第一條記
'** 錄和最后一條記錄的ID值,作為下一次翻頁(yè)的標(biāo)記,然后利用Top xx取
'** 出需要的數(shù)據(jù)顯示,同時(shí)又再對(duì)ID值進(jìn)行記錄。
'**
'** 【結(jié) 言】
'**
'** 本程序?yàn)楣蚕戆?,提供給各程序愛(ài)好者研究使用,若要轉(zhuǎn)載、散播、修
'** 改或作其他用途,請(qǐng)尊重作者的辛勞,注明出處。
'** 如果本程序中有錯(cuò)漏、非最優(yōu)化等缺點(diǎn),請(qǐng)到www.csdn.net的Web開(kāi)發(fā)/
'** ASP欄目中發(fā)表討論,為了中國(guó)軟件事業(yè)的發(fā)展,請(qǐng)不要固步自封:)
'**
'********************************************************************  
Option Explicit
'Response.Flush
Dim BeginTime,EndTime
BeginTime=Timer
Dim conn,SQLstr,Rs,DefRecordNum,CursorBegin,CursorEnd,CurPageNum,hav
DefRecordNum=20
'--------------獲取相關(guān)參數(shù)----------
If Request("CursorBegin")="" Then CursorBegin=0 Else CursorBegin=Request("CursorBegin")
If Request("CursorEnd")="" Then CursorEnd=0 Else CursorEnd=Request("CursorEnd")
If Request("CurPageNum")<>"" Then
CurPageNum=CLng(Request("CurPageNum"))
If CurPageNum<=0 Then CurPageNum=1
Else
CurPageNum=1
End If
hav=Request("hav")
If hav="" Then hav="next"
'----------------End-----------------
'------------顯示翻頁(yè)內(nèi)容函數(shù)--------
Function TurnPageFS(DispRecordNum)
Dim n
While Not(Rs.Eof) And n<DispRecordNum
n=n+1
Response.Write "<tr>"&_
"<td bgcolor='efefef'>"&Rs(0)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(1)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(2)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(3)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(4)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(5)&"</td>"&_
"</tr>"
If n=1 Then CursorBegin=Rs(0)
If n=DefRecordNum or Rs.Eof Then CursorEnd=Rs(0)
Rs.MoveNext
Wend
End Function
'-------------連接數(shù)據(jù)庫(kù)-------------
Set conn=Server.CreateObject("Adodb.Connection")
'SQLstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.Mappath("mldata.mdb")
SQLstr="Driver={SQL Server};server=arbiter;uid=arbiter;pwd=123456;database=mldata"
conn.Open SQLstr
'---------統(tǒng)計(jì)總記錄數(shù)/總頁(yè)數(shù)---------
'-PS:推薦使用count(ID),ID為自動(dòng)編號(hào)且索引,否則速度有可能大打折扣
'-PS:此統(tǒng)計(jì)是本程序中最耗資源的一部分,如果取消這段程序,速度會(huì)快上10倍左右
Dim TotalRecords,TotalPages
SQLstr="Select count(ID) As RecordSum From ABC"
Set Rs=conn.Execute(SQLstr,0,1)
TotalRecords=Rs("RecordSum")
TotalPages=Abs(Int(TotalRecords/DefRecordNum*(-1)))
Rs.Close
Set Rs=Nothing
'--------根據(jù)hav選擇相應(yīng)的SQL字串-----
Select Case(hav)
Case "back"
CursorEnd=CursorBegin
SQLstr="Select Top "&DefRecordNum&"_
ID,Title,FileName,K,ImgSize,NameSon _
From ABC Where ID<"&CursorBegin&_
" And ID In (Select Top "&DefRecordNum_
&" ID From ABC Where ID<"&CursorBegin_
&" order by ID DESC) order by ID"
Case "next"
SQLstr="Select Top "&DefRecordNum_
&" ID,Title,FileName,K,ImgSize,NameSon From ABC Where ID>"&CursorEnd&_
" order by ID"
End Select
Set Rs=conn.Execute(SQLstr,0,1)
%>
<html>
<head>
<title>"無(wú)限流"分頁(yè)程序  作者:Arbiter</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">td,br,div,p,body {font-size:12px}</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="#E2F5FE">
<tr align="center"> 
<td colspan="2"><%Response.Write CurPageNum&"/"&TotalPages&"頁(yè) 總記錄數(shù):"&TotalRecords%></td>
<td><a href="mllist.asp">首頁(yè)</a> <a href=javascript:turnpage('back');>上一頁(yè)</a> 
<a href=javascript:turnpage('next');>下一頁(yè)</a> </td>
</tr>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="3" bgcolor="#CCCCCC">
<tr> 
<td>ID</td>
<td>Title</td>
<td>FileName</td>
<td>大小</td>
<td>尺寸</td>
<td>類(lèi)別</td>
</tr>
<%
TurnPageFS(DefRecordNum)
Rs.Close
Set Rs=Nothing
conn.Close
Set conn=Nothing
%> 
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="#E2F5FE">
<tr align="center"> 
<td colspan="2"><%Response.Write CurPageNum&"/"&TotalPages&"頁(yè) 總記錄數(shù):"&TotalRecords%></td>
<td><a href="mllist.asp">首頁(yè)</a> <a href=javascript:turnpage('back');>上一頁(yè)</a> 
<a href=javascript:turnpage('next');>下一頁(yè)</a> </td>
</tr>
</table>
<%
EndTime=Timer
Response.Write "<br>程序執(zhí)行時(shí)間:"&(EndTime-BeginTime)*1000&"毫秒"
Response.Write " 第一條記錄的ID值(CursorBegin)="&CursorBegin&" "
Response.Write "最后一條記錄的ID值(CursorEnd)="&CursorEnd&"<br><br>"
%>
<script language="javascript">
function turnpage(func){
var CurPageNum=<%=CurPageNum%>; //取得當(dāng)前頁(yè)碼
var CursorBegin=<%=CursorBegin%>; //取得第一個(gè)顯示的記錄的ID值
var CursorEnd=<%=CursorEnd%>; //取得最后一個(gè)顯示的記錄的ID值
var TotalPages=<%=TotalPages%>; //取得頁(yè)面總數(shù) 
var BackUrl='mllist.asp?CurPageNum='+(CurPageNum-1)+'&CursorBegin='+CursorBegin+'&CursorEnd='+CursorEnd+'&hav=back';
var NextUrl='mllist.
asp?CurPageNum='+(CurPageNum+1)+'&CursorBegin='+CursorBegin+'&CursorEnd='+CursorEnd+'&hav=next';
if(CurPageNum<=1 && func=='back'){
location.href='#';
}else if(CurPageNum>=TotalPages && func=='next'){
location.href='#';
}else if(func=='back'){
location.href=BackUrl;
}else if(func='next'){
location.href=NextUrl;
}
}
</script>
</body>
</html>  
asp?CurPageNum='+(CurPageNum+1)+'&CursorBegin='+CursorBegin+'&CursorEnd='+CursorEnd+'&hav=next';
if(CurPageNum<=1 && func=='back'){
location.href='#';
}else if(CurPageNum>=TotalPages && func=='next'){
location.href='#';
}else if(func=='back'){
location.href=BackUrl;
}else if(func='next'){
location.href=NextUrl;
}
}
</script>
</body>
</html>  
Cnbruce的代碼:
分頁(yè)樣例:[首頁(yè)] [上頁(yè)] [下頁(yè)] [尾頁(yè)] [頁(yè)次:4/5頁(yè)] [共86篇 20篇/頁(yè)] 轉(zhuǎn)到:_ 頁(yè)
以下為公用代碼,必須具備。
<%filepath=request.servervariables("path_info")%>
<%page=1 '設(shè)置變量初始值PAGE=1
page=request.querystring("page") 'page值為接受值 
rs.PageSize = 20 '每頁(yè)顯示記錄數(shù)
if Not IsEmpty(trim(Request("Page"))) then '如果PAGE已經(jīng)初始化...
Page = CInt(Request("Page")) '接收PAGE并化為數(shù)字型賦給PAGE變量 
if Page > rs.PageCount then '如果接收的頁(yè)數(shù)大于總頁(yè)數(shù)
rs.AbsolutePage = rs.PageCount '設(shè)置當(dāng)前顯示頁(yè)等于最后頁(yè) 
elseif Page <= 0 then '如果page小于等于0
Page = 1 '設(shè)置PAGE等于第一頁(yè)
else
rs.AbsolutePage = Page '如果大于零,顯示當(dāng)前頁(yè)等于接收的頁(yè)數(shù) 
end if
End if
Page = rs.AbsolutePage%>
第一種分頁(yè)
<%if rs.pagecount<>1 and rs.pagecount<>0 then%>'首先判斷頁(yè)總數(shù)不為1和0
<%if page>1 then%>
<%if page<rs.pagecount then %>
[<a Href="<%=filepath%>?Page=<% = 1%>">首頁(yè)</a>]
[<a Href="<%=filepath%>?Page=<% = page -1 %>">上一頁(yè)</a>]
[<a Href="<%=filepath%>?Page=<% = page + 1%>">下一頁(yè)</a>]
[<a Href="<%=filepath%>?Page=<% = rs.PageCount%>">尾頁(yè)</a>]
<%else%>
[<a Href="<%=filepath%>?Page=<% = 1%>">首頁(yè)</a>]
[<a Href="<%=filepath%>?Page=<% = page -1 %>">上一頁(yè)</a>] 
[下一頁(yè)] [尾頁(yè)]
<% end if %>
<%else%>
[首頁(yè)] [上一頁(yè)]
[<a Href="<%=filepath%>?Page=<% = page + 1%>">下一頁(yè)</a>] 
[<a Href="<%=filepath%>?Page=<% = rs.PageCount%>">尾頁(yè)</a>]
<%end if %>
<%else%>
[首頁(yè)] [上一頁(yè)] [下一頁(yè)] [尾頁(yè)]
<%end if%>
第二種分頁(yè)
<%if rs.pagecount<>1 and rs.pagecount<>0 then%>
<%if page>1 then%>
[<a Href="<%=filepath%>?Page=<% = 1%>">首頁(yè)</a>]
[<a Href="<%=filepath%>?Page=<% = page -1 %>">上一頁(yè)</a>]
<%if page<rs.pagecount then %>
[<a Href="<%=filepath%>?Page=<% = page + 1%>">下一頁(yè)</a>]
[<a Href="<%=filepath%>?Page=<% = rs.PageCount%>">尾頁(yè)</a>] 
    <%else%>
    [下一頁(yè)] [尾頁(yè)]
<% end if %>
<%else%>
[首頁(yè)] [上一頁(yè)]
[<a Href="<%=filepath%>?Page=<% = page + 1%>">下一頁(yè)</a>] 
[<a Href="<%=filepath%>?Page=<% = rs.PageCount%>">尾頁(yè)</a>]
<%end if %>
<%else%>
[首頁(yè)] [上一頁(yè)] [下一頁(yè)] [尾頁(yè)]
<%end if%>
第三種
<%if rs.pagecount<>1 and rs.pagecount<>0 then%>
<%if page<rs.pagecount then%>
<%if page=1 then %>
[首頁(yè)] [上一頁(yè)]
<%else%>
[<a Href="<%=filepath%>?Page=<% = 1%>">首頁(yè)</a>]
[<a Href="<%=filepath%>?Page=<% =page -1 %>">上一頁(yè)</a>]
<% end if %>
[<a Href="<%=filepath%>?Page=<% = page + 1%>">下一頁(yè)</a>] 
[<a Href="<%=filepath%>?Page=<% = rs.PageCount%>">尾頁(yè)</a>]
<%else%>
[<a Href="<%=filepath%>?Page=<% = 1%>">首頁(yè)</a>]
[<a Href="<%=filepath%>?Page=<% =page -1 %>">上一頁(yè)</a>]
[下一頁(yè)] [尾頁(yè)]
<%end if %>
<%else%>
[首頁(yè)] [上一頁(yè)] [下一頁(yè)] [尾頁(yè)]
<%end if%>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 县级市| 商水县| 阿鲁科尔沁旗| 海晏县| 张家港市| 芜湖县| 广汉市| 呼和浩特市| 图木舒克市| 汕头市| 柞水县| 张家港市| 株洲县| 商都县| 湖南省| 大英县| 宜兴市| 乌鲁木齐市| 获嘉县| 连州市| 赤水市| 旺苍县| 霍林郭勒市| 同心县| 通化县| 衡山县| 奈曼旗| 丰镇市| 九寨沟县| 湟源县| 望都县| 湘西| 双牌县| 墨玉县| 长宁区| 临桂县| 林州市| 营山县| 岳阳县| 巧家县| 怀柔区|