ASP Article System Solution

Source: Internet
Author: User
Tags define include query

First of all thanks to V37 to help me, this solution to show the "last article next" and related articles of the problem,

Post it for everyone to share.

I've seen a post that uses id+1 and ID-1 to judge the next article

In the process of using a problem found: when the deletion of an article in the database, will cause the ID discontinuity,

If you use id+1 and ID-1 to judge, there will be no record of the problem, in this program,

The ID of the next article is found by querying the first record that is greater than the current ID.

The query is less than the first record of the current ID to find the ID of the previous one, so that it can be displayed normally even if the ID is not contiguous.

As for the related article display is in the data table to add a boardid field to distinguish between different articles columns,

It's OK to add a boardid number to each new article.

When you display an article, you can query the database based on Boardid to show the relevant articles.

The fields in datasheet articles have id,boardid,title,content,author,addtime.

<!--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 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 "right" >
<span style= "font-size:9pt color: #efefef" > Author: <%= rs ("author")%></span></div> </span> &LT;/TD&GT;&LT;/TR&GT;&LT;TR&GT;&LT;TD colspan= "2" >
<span style= "font-size:9pt color: #efefef" >
<!--the data of the database out, after encoding output, keep the format of the input is unchanged-->
<%= replace (server. HTMLEncode (RS ("content")), Chr ("<br>")%></span></td></tr><% a1=rs ("id")%> &LT;TR&GT;&LT;TD width= "align=" "Right" >
<!--call the previously defined function that displays the previous article-->
<% Thehead%>
</td>
&LT;TD width= "257" align= "right" >
<!--call the function defined earlier to display the next article-->
<% Thenext%></td></tr>
<% Rs. MoveNext
Loop
%&GT;&LT;/TABLE&GT;&LT;/TD&GT;&LT;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 while not Rs. EOF%>
<table width= "207" border= "0" cellspacing= "2" cellpadding= "2" >
<tr>
&LT;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-->


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.