First of all, thanks to V37 to help me, this solution to show the "last article" and related articles of the problem, posted out for everyone to share.
I've seen a post that uses id+1 and ID-1 to judge the next article in the use of the process to find a problem: when the deletion of an article in the database, will cause the ID discontinuity, if the use of id+1 and ID-1 to judge the problem can not find records, in this program, By querying the first record that is larger than the current ID to find the next ID, the query is less than the first record of the current ID to find the ID of the previous one, so that even if the ID is discontinuous, it can be displayed normally.
As for the relevant article display is in the data table to add a boardid field to distinguish between different article columns, add a new article each time added Boardid number on it, display an article according to Boardid to query the database can show the relevant articles.
The fields in datasheet articles have Id,boardid,title,content,author,addtime
Copy Code code as follows:
<!--program started-->
' Define a thenext function to find the ID for the next one, and if the current record is the last record, the output text ' is not '
<%
function Thenext
Newrs=server. CreateObject ("Adodb.recordset")
Sql= ' SELECT top 1 * articles where id> ' &a1& ' ORDER by ID '
Set Newrs=conn.execute (SQL)
If Newrs.eof Then
Response. Write ("no")
Else
A2=newrs ("id")
Response. Write ("<a href= ' view.asp?id=" &a2& "' > Next </a>")
End If
End Function
%>
' Define a thehead function to find the ID for the next article, and if the current record is already the first record, the output text ' is not '
<%
function Thehead
Headrs=server. CreateObject ("Adodb.recordset")
Sql= "SELECT top 1 * articles where id<" &a1& "ORDER BY id DESC"
Set Headrs=conn.execute (SQL)
If Headrs.eof Then
Response. Write ("no")
Else
A0=headrs ("id")
Response. Write ("<a href= ' view.asp?id=" &a0& "' > Previous </a>")
End If
End Function
%>
' Database connection File
<!--#include file= "conn.asp"-->
' Get the ID passed over, show the article title author and content
<%
Id=request ("id")
Sql= "SELECT * from articles where id=" &id
Set Rs=conn.execute (SQL)
%>
<% boardid=rs ("Boardid")%>
<title> article System-<% =rs ("title")%></title><body leftmargin= "0" topmargin= "0" >
<!--#include file= "top.asp"-->
<%
Do but 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" > Author: <%= rs ("author")%></span> </div>
</span></td>
</tr>
<tr>
<TD colspan= "2" ><span style= "font-size:9pt color: #efefef" ><!--take the data out of the database, encode and output, and keep the format of the input unchanged--> <%= replace (server. HTMLEncode (RS ("content"), CHR, "<br>")%></span></td>
</tr>
<% a1=rs ("id")%>
<tr>
<TD width= "align= right" ><!--invoke the function previously defined to display the previous article--><% Thehead%></td>
<TD width= "257" align= "right" ><!--invoke the function defined earlier to display the next article--><% Thenext%></td>
</tr>
<% Rs. Movenext%>
<%Loop%>
</table></td>
<TD width= "217" valign= "Top" align= "left" > Related articles:
' According to the column number of the current article, find the article in the same column
<%
Sql= "SELECT * from articles where boardid=" &boardid& "
Set Rs=conn.execute (SQL)
%>
<%
Do but not Rs. Eof
%>
<table width= "207" border= "0" cellspacing= "2" cellpadding= "2" >
<tr>
<TD height= "><a href=" view.asp?id=<%=rs ("id")%> "><%= rs (" title ")%></a></td >
</tr>
</table>
<% Rs. Movenext%>
<%Loop%>
</td>
</tr>
</table>
<!--#include file= "copyright.asp"-->
</body>
<!--program End-->
Current 1/2 page
12 Next read the full text