1. 程式人生 > >asp實現上一篇下一篇

asp實現上一篇下一篇

<!--程式開始-->
'定義一個thenext函式來找出下一篇的ID,如果當前記錄已經是最後一條記錄,則輸出文字“沒有了”
<%
function thenext
newrs=server.CreateObject("adodb.recordset")
sql="select top 1 * from articles where id>"&a1&" order by id"
set newrs=conn.execute(sql)
if newrs.eof then
response.Write("沒有了")
else
a2=newrs("id")
response.Write("<a href='view.asp?id="&a2&"'>下一篇</a>")
end if
end function
%>
'定義一個thehead函式來找出下一篇的ID,如果當前記錄已經是最前面的一條記錄,則輸出文字“沒有了”
<%
function thehead
headrs=server.CreateObject("adodb.recordset")
sql="select top 1 * from articles where id<"&a1&" order by id desc"
set headrs=conn.execute(sql)
if headrs.eof then
response.Write("沒有了")
else
a0=headrs("id")
response.Write("<a href='view.asp?id="&a0&"'>上一篇</a>")
end if
end function
%>
'資料庫連線檔案
<!--#include file="conn.asp"-->
'取得傳遞過來的ID,顯示文章標題作者和內容
<%
id=request("id")
sql="select * from articles where id="&id
set rs=conn.execute(sql)
%>
<% boardid=rs("boardid") %>
<title>文章系統-<% =rs("title") %></title><body leftmargin="0" topmargin="0">
<!--#include file="top.asp" -->
<%
Do While Not rs.EOF
%>
<table width="773" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
<td width="576" align="left">
<table width="557" border="0" cellspacing="5" cellpadding="4" align="left">
        <tr>
          <td colspan="2" align="center"><span style="font-size:9pt color:#efefef"><%= rs("title") %><br>
            <div align="right"><span style="font-size:9pt color:#efefef">作者:<%= rs("author") %></span></div>
            </span></td>
        </tr>
        <tr>
          <td colspan="2" ><span style="font-size:9pt color:#efefef"><!--將資料庫的資料取出,經過編碼後輸出,保持輸入時的格式不變--><%= replace(server.HTMLEncode(rs("content")),chr(13),"<br>") %></span></td>
        </tr>
<% a1=rs("id") %>
        <tr>
          <td width="269" align="right"><!--呼叫前面定義的顯示上一篇的函式--><% thehead %></td>
          <td width="257" align="right"><!--呼叫前面定義的顯示下一篇的函式--><%  thenext %></td>
        </tr>
        <% rs.MoveNext%>
        <%Loop%>
      </table></td>
    <td width="217"  valign="top" align="left">相關文章:
'根據當前文章的欄目號,找出同一欄目的文章   
<%
sql="select * from articles where boardid="&boardid&""
set rs=conn.execute(sql)
%>
<%
    Do While Not rs.EOF
    %>
<table width="207" border="0" cellspacing="2" cellpadding="2">
  <tr>
          <td height="20"><a href="view.asp?id=<%=rs("id")%>"><%= rs("title") %></a></td>
  </tr>
</table>
<% rs.MoveNext%>
<%Loop%>
    </td>
  </tr>
</table>
<!--#include file="copyright.asp" -->
</body>
<!--程式結束-->