asp快速分頁代碼_ASP教程
推薦:Asp文件操作函數(shù)集% '===============asp 文件操作函數(shù)集1.0版本========================= ' 整理作者: 張輝 ' 程序員代號:WJ008 ' 整理時間:2008年 6 月 1 日 ' 關(guān)注地址:www.wj008.net ' 所有函數(shù)使用的文件地址 全部使用絕對地址 '============================================
<%@ language = "vbscript" codepage = 936%>
<%
option explicit '強制定義變量
dim idcount'記錄總數(shù)
dim pages'每頁條數(shù)
dim pagec'總頁數(shù)
dim page'頁碼
dim pagenc '每頁顯示的分頁頁碼數(shù)量=pagenc*2+1
pagenc=2
dim pagenmax '每頁顯示的分頁的最大頁碼
dim pagenmin '每頁顯示的分頁的最小頁碼
page=clng(request("page"))
dim start'程序開始的時間
dim endt'程序結(jié)束的時間
dim datafrom'數(shù)據(jù)表名
datafrom="table1"
dim conn,rs
dim datapath '數(shù)據(jù)庫路經(jīng)
dim sqlid'本頁需要用到的id
dim myself'本頁地址
myself = request.servervariables("path_info")
dim sql'sql語句
dim taxis'排序的語句
'taxis="order by id asc" '正排序
taxis="order by id desc" '倒排序
dim i'用于循環(huán)的整數(shù)
start=timer()
datapath="db.mdb"'數(shù)據(jù)庫
pages=30
'連接打開數(shù)據(jù)庫
dim db
db="db.mdb" '定義數(shù)據(jù)庫路徑及名稱
set conn = server.createobject("adodb.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(db)
if err.number <> 0 then
response.write "數(shù)據(jù)庫鏈接出錯!"
response.end()
end if
'獲取記錄總數(shù)
sql="select count(id) as idcount from ["& datafrom &"]"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,0,1
idcount=rs("idcount")'獲取記錄總數(shù)
if(idcount>0) then'如果記錄總數(shù)=0,則不處理
if(idcount mod pages=0)then'如果記錄總數(shù)除以每頁條數(shù)有余數(shù),則=記錄總數(shù)/每頁條數(shù)+1
pagec=int(idcount/pages)'獲取總頁數(shù)
else
pagec=int(idcount/pages)+1'獲取總頁數(shù)
end if
'獲取本頁需要用到的id============================================
'讀取所有記錄的id數(shù)值,因為只有id所以速度很快
sql="select id from ["& datafrom &"] " & taxis
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
rs.pagesize = pages '每頁顯示記錄數(shù)
if page < 1 then page = 1
if page > pagec then page = pagec
if pagec > 0 then rs.absolutepage = page
for i=1 to rs.pagesize
if rs.eof then exit for
if(i=1)then
sqlid=rs("id")
else
sqlid=sqlid &","&rs("id")
end if
rs.movenext
next
'獲取本頁需要用到的id結(jié)束============================================
end if
%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>快速分頁</title>
<link rel="stylesheet" href="page.css" type="text/css">
</head>
<body bgcolor="#f2f2f2" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" cellpadding="20" cellspacing="0">
<tr>
<td valign="middle"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td valign="top" bgcolor="#ffffff"><br> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="zw">
<tr>
<td><strong><font color="#ff6600">快速分頁</font></strong></td>
</tr>
</table>
<br>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="cccccc" class="zw">
<tr align="center" bgcolor="#9fcb07">
<td width="9%"><strong>ID</strong></td>
<td width="37%"><strong>主題</strong></td>
<td width="33%"><strong>內(nèi)容</strong></td>
<td width="21%"><strong>時間</strong></td>
</tr>
<%
if(idcount>0 and sqlid<>"") then'如果記錄總數(shù)=0,則不處理
'用in刷選本頁所語言的數(shù)據(jù),僅讀取本頁所需的數(shù)據(jù),所以速度快
sql="select [id],[aaaa],[bbbb],[cccc] from ["& datafrom &"] where id in("& sqlid &") "&taxis
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,0,1
while(not rs.eof)'填充數(shù)據(jù)到表格
%>
<tr bgcolor="#ffffff">
<td align="center"><%=rs(0)%></td>
<td><%=rs(1)%></td>
<td><%=rs(2)%></td>
<td align="center"><%=rs(3)%></td>
</tr>
<%
rs.movenext
wend
%>
</table>
<br>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="zw">
<tr align="center">
<td align="left">共有<strong><font color="#ff6600"><%=idcount%></font></strong>條記錄,<strong><font color="#ff6600"><%=page%></font></strong>/<%=pagec%>,每頁<strong><font color="#ff6600"><%=pages%></font></strong>條。</td>
</tr>
</table>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="zw">
<tr align="center">
<td align="right">
<%
'設(shè)置分頁頁碼開始===============================
pagenmin=page-pagenc'計算頁碼開始值
pagenmax=page+pagenc'計算頁碼結(jié)束值
if(pagenmin<1) then'如果頁碼開始值小于1則=1
pagenmin=1
end if
if(page>1) then'如果頁碼大于1則顯示(第一頁)
response.write ("<a href='"& myself &"?page=1'><font color='#000000'>第一頁</font></a> ")
end if
if(pagenmin>1) then'如果頁碼開始值大于1則顯示(更前)
response.write ("<a href='"& myself &"?page="& page-(pagenc*2+1) &"'><font color='#000000'>更前</font></a> ")
end if
if(pagenmax>pagec) then'如果頁碼結(jié)束值大于總頁數(shù),則=總頁數(shù)
pagenmax=pagec
end if
for i = pagenmin to pagenmax'循環(huán)輸出頁碼
if(i=page) then
response.write ("<font color='#ff6600'><strong>"& i &"</strong></font> ")
else
response.write ("[ <a href="& myself &"?page="& i &"><font color='#000000'>"& i &"</font></a> ] ")
end if
next
if(pagenmax<pagec) then'如果頁碼結(jié)束值小于總頁數(shù)則顯示(更后)
response.write ("<a href='"& myself &"?page="& page+(pagenc*2+1) &"'><font color='#000000'>更后</font></a> ")
end if
if(page<pagec) then'如果頁碼小于總頁數(shù)則顯示(最后頁)
response.write ("<a href='"& myself &"?page="& pagec &"'><font color='#000000'>最后頁</font></a> ")
end if
'設(shè)置分頁頁碼結(jié)束===============================
%><script language="javascript">
<!--
function gopage() {
window.location.href="<%=myself%>?page="+ page.value;
}
//-->
</script>
轉(zhuǎn)到
<input name="page" type="text" value="<%=page%>" size="5">頁
<input type="button" name="submit" value="跳轉(zhuǎn)" ></td>
</tr>
</table>
<%
end if
%>
<br>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="zw">
<tr>
<td align="center">
<p>
<%
endt=timer()
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
<%=formatnumber((endt-start)*1000,3)%>毫秒 </p>
<p><a href="http://stone-stone.vip.sina.com/" target="_blank">STONE空間</a></p></td>
</tr>
</table>
<br></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
分享:ASP使用FCKEditor的設(shè)置技巧1、默認語言 打開fckconfig.js文件(相對FCKeditor文件夾,以下同),把自動檢測語言改為不檢測,把默認語言改為簡體中文: 程序代碼 FCKConfig.AutoDetectLanguage = false ; FCKConfig.DefaultLanguage = 'zh-cn' ; 2、字體列表 打開fckconfig.js文件,在字體列表中
- 相關(guān)鏈接:
- 教程說明:
ASP教程-asp快速分頁代碼
。