才子分頁類

<%@language="vbscript" codepage="936"%>
<%
'定義數據連接
option explicit
on error resume next
dim startime,endtime
startime=timer()
dim db,conn,rs
db = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("./db.mdb")
set conn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
conn.open db
%>
<%
'**************
'分頁導航欄函數
'輸出wzpage值
'**************
Function pagination(pagecount)
   Dim wzpage,wzpagecount,pagenum,boardid
   boardid = Request.QueryString("board_id")
   If boardid = 0 Then boardid = 1
       If Len(Request.QueryString("page"))<>0 Then
          wzpage = clng(Request.QueryString("page"))
         Else
          wzpage =1
       End If
       If wzpage <= 0 Then wzpage =1
       pagenum = (wzpage / 10)*10+1
       If wzpage mod 10 = 0 Then pagenum = (wzpage / 10)*10-9
       If wzpage > 10 Then
         Response.Write ("<font face=""webdings"">")
            Response.Write ("<a href=""?board_id="& boardid &"&page=1"" title=""首頁"">9</a>")
   Response.Write ("<a href=""?board_id="& boardid &"&page="& pagenum-1 &""" title=""前十頁"">7</a>")
            Response.Write ("</font>")
    End If
       For pagenum = pagenum To pagenum + 9
           If pagenum = wzpage Then
                  Response.Write ("<font color=""#ff0000"">")
                  Response.Write (" ["& pagenum &"] ")
                  Response.Write ("</font>")
        Else
                  Response.Write (" <a href=""?board_id="& boardid &"&page="& pagenum &""">")
                  Response.Write ("["& pagenum &"]")
                  Response.Write ("</a> ")
   End If
         If pagenum >= pagecount Then Exit For
       Next
     If wzpage < (pagecount - (pagecount / 10))  Then
         Response.Write ("<font face=""webdings"">")
            Response.Write ("<a href=""?board_id="& boardid &"&page="& pagenum &"""  title=""後十頁"">8</a>")
   Response.Write ("<a href=""?board_id="& boardid &"&page="& pagecount &"""  title=""末頁"">:</a>")
            Response.Write ("</font>")
   End If
End Function
%>
<%
dim rssql,getstring
getstring = clng(request.querystring("board_id"))
if getstring = 0 then getstring = 1

'******************************************
'取文章總數及每頁重複顯示條數,準備分頁
'wzcount 文章總數
'wzrep 重複顯示條數
'wzpage 分頁參數id
'wzpagecount 總頁數
'******************************************
dim wzcount,wzrep,wzpage,wzpagecount,wzpagerep,boardstr
wzrep = 30
'rssql = "select count(id) from `table1`"
'rs.open rssql,conn,0,1,&h0001
wzcount = conn.execute ("select count(id) from `table1`",0,1)(0)
'rs.close
wzpagecount = abs(int(-abs(wzcount/wzrep)))
wzpage = clng(request.querystring("page"))
if len(wzpage) = 0 or wzpage = 0 then wzpage = 1

%>
<html>
<head>
<title>分頁測試</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body,table,td,p,li {font-size:12px}
a {font-size:12px;color:#000000;text-decoration: none}
INPUT {
 BORDER-TOP-WIDTH: 1px;
 PADDING-RIGHT: 1px;
 PADDING-LEFT: 1px;
 BORDER-LEFT-WIDTH: 1px;
 FONT-SIZE: 12px;
 BORDER-LEFT-COLOR: #cccccc;
 BORDER-BOTTOM-WIDTH: 1px;
 BORDER-BOTTOM-COLOR: #cccccc;
 PADDING-BOTTOM: 1px;
 BORDER-TOP-COLOR: #cccccc;
 PADDING-TOP: 1px;
 HEIGHT: 18px;
 BORDER-RIGHT-WIDTH: 1px;
 BORDER-RIGHT-COLOR: #cccccc;
 BACKGROUND-COLOR: #F2F8FF
}
-->
</style>
</head>

<body>
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center" height="30">
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<table width="760" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#ffffff" bordercolorlight="#cccccc">
  <tr align="center">
    <td width="60">ID</td>
    <td width="150">標題</td>
    <td width="*">內容(顯示前20個字)</td>
    <td width="150">時間</td>
  </tr>
  <%
'取文章列表
rssql = "select id,aaaa,bbbb,cccc from `table1` order by id desc"
rs.open rssql,conn,1,1,&h0001
'根據分頁參數獲取當前頁面紀錄
rs.absoluteposition=rs.absoluteposition+((abs(wzpage)-1)*wzrep)
'顯示文章標題列表
if rs.eof or rs.bof then%>
<tr bgcolor="">
    <td >暫無記錄</td>   
  </tr>
<% else
dim i,bgcolor
for i = 0 to wzrep-1
 if rs.eof then exit for
'while not rs.eof and i <= wzrep
 bgColor="#FFFFFF"
 if i mod 2=0 then bgColor="#DFEFFF"
%>
  <tr bgcolor="<%=bgColor%>">
    <td width="60"><%=rs(0)%></td>
    <td width="150"><%=rs(1)%></td>
    <td width="*"><%=left(rs(2),20)%></td>
    <td width="150"><%=rs(3)%></td>
  </tr>
<%
rs.movenext
'i=i+1
'wend
next
end if
%>
</table>
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center">
  <tr>
    <td align="left" width="200">共<font color=red><%= wzcount%></font>條 <font color=red><%= wzrep%></font>/頁 共<font color=red><%= wzpagecount%></font>頁</td>
 <td align="right"> <%= pagination(wzpagecount)%></td>
  </tr>
</table>
 
<table width="760" border="0" align="center" cellpadding="2" cellspacing="2">
  <tr>
    <td align="center">
      <%endtime=timer()%>
      本頁面執行時間:<%=formatnumber((endtime-startime)*1000,3)%>毫秒</td>
  </tr>
</table>
</body>
</html>
<%
'釋放資源
rs.close
set rs = nothing
conn.close
set conn = nothing
%>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章