給萬博系統的新聞系統增加分頁功能[配有詳細說明]_ASP基礎

來源:互聯網
上載者:User
給萬博系統的新聞系統增加分頁功能,無需修改資料庫,只需改變一個檔案,就可以了.
如果將背景Webediter增加一個插入分頁符,那就更完美了.我還沒加這個.

本例是在後台錄入新聞時,在需要分頁的位置插入分頁符: {$html_page$} 就可以了.

代碼如下,有詳細說明
newsshow.asp

<!--#include file="siteinfo.asp"-->
<HTML>
<HEAD>
<TITLE><%=sitename%></TITLE>
<META HTTP-EQUIV="Content-Type" C>
<link href="images/CSS.css" type=text/css rel=stylesheet>
</HEAD>
<body  topmargin="0">
<table width="780" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="3"><!--#include file="top.asp"--></td>
  </tr>
  <tr>
    <td width="145" align="left" valign="top"><!--#include file="left.asp" --></td>
    <td align="left" valign="top" ><table width="625"  border="0" cellspacing="0" cellpadding="0">

        <tr>
          <td width="17" height="20"> </td>
          <td width="598"> </td>
          <td width="10"> </td>
        </tr>
        <tr >
          <td width="17"><% idd=trim(request.querystring("id"))
             set rsr=server.createobject("adodb.recordset")
             sql="select * from News where  Putout=true and id="&idd
             rsr.open sql,conn,1,3
    if not rsr.eof then

    Newcontent=rsr("Newcontent")
    Newtitle=rsr("Newtitle")
                Putman=rsr("Putman")
    kig=rsr("kig")
    kig=kig+1
    addtime=rsr("addtime")  
    rsr("kig")=kig
    rsr.update
    else
    response.Write"找不到記錄,發生導常錯誤,請聯絡管理員!"
    end if  
'這裡要處理接收到的分頁參數,以此來進行顯示第幾頁的內容
'下面這兩句就是如果沒有page這個參數傳來就讓變數pageNum取顯示第一頁的值:0
If Request("page")="" Then
pageNum=0
'否則就給變數賦值為傳遞來的page裡的參數,來顯示其他頁
Else
pageNum=Request("page")
End if
%>
<%
'如果加了可選執行UBB代碼,可以加上下面的代碼
'rs("NoUBB")是資料庫裡關于禁用UBB的欄位,0為禁用,1為執行
'If rsr("NoUBB")=0 then
'為避免和文章內容相連出現錯誤,用Replace函數把分頁代碼“{$html_page$}”的前後各加一個全形的
'rs("content")是資料庫裡本文的欄位,在這裡加上UBB或者禁用UBB
Content=Replace(Newcontent,"{$html_page$}"," {$html_page$} ")
'Elseif rsr("NoUBB")=1 then
'Content=Replace((ubb(Newcontent)),"{$html_page$}"," {$html_page$} ")
'End if
%></td>
          <td height="22" align="center" class="NEWS_title"><%=Newtitle%><br>
<hr size="1" noshade  color="#666666"></td>
          <td width="10"> </td>
        </tr>
        <tr>
          <td rowspan="3"> </td>
          <td height="303" valign="top" ><%
'這裡就是關鍵了
'我們用split函數將文章分段取出存入變數content
ContentStr=split(Content,"{$html_page$}")
'按照剛才從URL參數中取得的要顯示那面的那個變數,就迴圈顯示一頁
For i=pageNum to pageNum
%>
<!--這裡將是文章本文內容-->
<%=ContentStr(i) %>
<% Next %></td>
          <td rowspan="3"> </td>
        </tr>
        <tr>
          <td height="8" valign="top">  </td>
        </tr>
        <tr>
          <td height="8" align="center" valign="top">本文共分
<%
'分頁的地方,用ubound(ContentStr)取得文章一共分為幾頁,注意這裡是從0開始,所以總頁數需要加1
For p = 0 to ubound(ContentStr)
'連結還是本頁面,只不過文章ID參數後面還要加上一個分頁的參數:page
%> 
<a href="newsshow.asp?ID=<%=request("ID")%>&page=<%=p%>" class=""><%=p+1%></a>
<% Next %>頁</td>
        </tr>
        <tr>
          <td height="40"> </td>
          <td height="60" valign="bottom"><table width="100%"  border="0" cellpadding="5" cellspacing="1" bgcolor="#CECECE">
            <tr bgcolor="#FFFFFF" >
              <td width="16%" align="right" bgcolor="#CECECE" >發 布  者:</td>
              <td width="20%" bgcolor="#FFFFFF"> <%=Putman%></td>
              <td width="15%" align="right" bgcolor="#CECECE">添加時間:</td>
              <td width="20%" bgcolor="#FFFFFF"> <%=addtime%></td>
              <td width="15%" align="right" bgcolor="#CECECE">點  擊  數:</td>
              <td width="15%"><%=kig%></td>
            </tr>
          </table></td>
          <td> </td>
        </tr>
    </table></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="3"><!--#include file="bot.asp"--></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.