asp access 大資料量的分頁的方法

來源:互聯網
上載者:User

'本款分頁效果支援'分頁,分頁效果:首頁 上一頁 ... 2 3 4 5 6 7 ... 下一頁 最後一頁這種分頁模式,有論壇風格
'id title content status updatetime
'1 t1 c1 1 2010-5-26 21:16:06
'2 t2 c2 1 2010-5-26 21:16:09
'3 t3 c3 1 2010-5-26 21:16:12
'4 t4 c4 1 2010-5-26 21:16:15
'5 t5 c5 1 2010-5-26 21:16:23


DB="database/db1.mdb"
path=Server.MapPath(DB)
set conn=server.createobject("adodb.Connection")
connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source="&path
conn.Open connstr
Set rs=server.CreateObject("adodb.recordset")


%>

<!-- #include file="conn.asp" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <style>
  td{
 font-size:12px;
  }
  </style>
 </HEAD>

 <BODY>
 

 <TABLE border=1 cellspacing=0 cellpadding=0 width=500>
  <TR>
  <td align="center">ID</td>
  <TD height="22" align="center">標題</TD>
  <TD align="center">時間</TD>  
  </TR>
 <%
 '十萬條以上資料的分頁的方法
 '作者:wangsdong
 '來源:111cn.net
 '原創檔案,轉載請保留此資訊,謝謝
keyword=request("keyword")
page=request("page")
If page="" Or Not IsNumeric(page) then page=1 Else page=CInt(page)
page_size=2
q1=" and status>0"
If keyword<>"請輸入關鍵詞" and keyword<>"" then
 q1=q1&" and title like '%"&keyword&"%'"
end If
if page>1 then
 sql="select top "&page_size&" id,title,content,updatetime from news where 1=1 and id<(select min(id) from (select top "&(page-1)*page_size&" id from news where status>0"&q1&" order by id desc) as c1)" 
else  
 sql="select top "&page_size&" id,title,content,updatetime  from news where 1=1"  
end if
sql=sql&q1&" order by id desc" 
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
 do while not rs.eof
 id=rs("id")
 title=rs("title")
 content=rs("content")
 updatetime=rs("updatetime")
 '*************迴圈的內容開始************************
 %>
  <TR>
  <td><%=id%></td>
  <TD height="22"><%=title%></TD>
  <TD><%=updatetime%></TD>  
  </TR>
 <%
 '*************迴圈的內容結束************************
 rs.movenext
 loop
end if
rs.close
%>
<tr><td colspan="3" height="30" align="center">
<%
'分頁開始
'計算總頁數
page_count=1
sql="select count(*) as t from news where 1=1"&q1
rs.open sql,conn,1,1
if rs.eof then
else
 recordset_count=rs("t")
 if recordset_count mod page_size=0 then
  page_count=recordset_countpage_size
 else
  page_count=recordset_countpage_size+1
 end if
end if
rs.close
'分頁,分頁效果:首頁 上一頁 ... 2 3 4 5 6 7 ... 下一頁 最後一頁
if page=1 then
 response.write "首頁&nbsp;上一頁&nbsp;"
else
 response.write "<a href=""?page=1&keyword="&keyword&""">首頁</a>&nbsp;<a href=""?page="&page-1&"&keyword="&keyword&""">上一頁</a>&nbsp;"
end if
if page>4 then
 s=page-3
 response.write "..."
else
 s=1   
end if  
if page<=page_count-3 then
 e=page+3    
else
 e=page_count   
end if   
for i=s to e
 if i=page then
  response.write "<font color=""#FF8000""><b>"&i&"</b></font>&nbsp;"
 else
  response.write "<a href=""?page="&i&"&keyword="&keyword&""">"&i&"</a>&nbsp;"
 end if  
next

if page<page_count-3 then
 response.write "..."
end if
if page=CInt(page_count) then
 response.write "<span>下一頁&nbsp;最後一頁</span>"
else
 response.write "<span><a href=""?page="&page+1&"&keyword="&keyword&""">下一頁</a>&nbsp;<a href=""?page="&page_count&"&keyword="&keyword&""">最後一頁</a></span>"
end if 

%>

</td></tr>

 
 </TABLE>
 </BODY>
</HTML>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.