First of all, I would like to thank V37 Banzhu for helping me. This solution solves the problem of displaying "Previous article Next article" and related articles, and post it for everyone to share.
I saw a post that I used ID+1 and ID-1 to judge the "Previous article and next article". During the use, I found a problem: when deleting an article in the database, the ID will be discontinuous. If ID+1 and ID-1 are used to judge, the record will not be found. In this program, the ID of the next article is found by querying the first record larger than the current ID, and the first record smaller than the current ID to find the ID of the previous article. In this way, even if the ID is not continuous, it can be displayed normally.
As for the display of related articles, add a boardid field in the data table to distinguish different article columns. Add a boardid number every time you add a new article. When displaying an article, query the database according to the boardid to display the relevant articles.
The fields in the data table articles include id, boardid, title, content, author, addtime
The code copy is as follows:
<!--Program Start-->
'Define a thenext function to find the ID of the next article. If the current record is already the last record, the output text "no" is
<%
functionthenext
newrs=server.CreateObject("adodb.recordset")
sql="selecttop1*fromarticleswhereid>"&a1&"orderbyid"
setnewrs=conn.execute(sql)
ifnewrs.eofthen
response.Write("Not")
else
a2=newrs("id")
response.Write("<ahref='view.asp?id="&a2&"'>Next article</a>")
endif
endfunction
%>
'Define a thehead function to find the ID of the next article. If the current record is already the first record, the output text "no" is
<%
functionthehead
headrs=server.CreateObject("adodb.recordset")
sql="selecttop1*fromarticleswhereid<"&a1&"orderbyiddesc"
setheadrs=conn.execute(sql)
ifheadrs.eofthen
response.Write("Not")
else
a0=headrs("id")
response.Write("<ahref='view.asp?id="&a0&"'>Previous article</a>")
endif
endfunction
%>
'Database connection file
<!--#includefile="conn.asp"-->
'Get the passed ID to display the title author and content of the article
<%
id=request("id")
sql="select*fromarticleswhereid="&id
setrs=conn.execute(sql)
%>
<%boardid=rs("boardid")%>
<title>Article System-<%=rs("title")%></title><bodyleftmargin="0"topmargin="0">
<!--#includefile="top.asp"-->
<%
DoWhileNotrs.EOF
%>
<tablewidth="773"border="0"cellpacing="0"cellpadding="0"align="center">
<tr>
<tdwidth="576"align="left">
<tablewidth="557"border="0"cellpacing="5"cellpadding="4"align="left">