ASP article system solution implementation previous page next page 1/2 page

Source: Internet
Author: User

First of all, I would like to express my gratitude for the help of V37 bamboo. This solution solves the problem of displaying the "previous article" and related articles and posts them for sharing.
In the past, I saw a post about how to use ID + 1 and ID-1 to determine the next post. I found a problem during the usage process: When I delete an article in the database, the ID is not consecutive. If ID + 1 and ID-1 are used for determination, the record cannot be found. In this program, you can query the first record with the ID greater than the current ID to find the ID of the next record. The first record with the ID smaller than the current ID is queried to find the ID of the previous record, so that the ID can be displayed normally even if the ID is not consecutive.
As for the display of relevant articles, a boardid field is added to the data table to distinguish different article columns. You can add the boardid number each time you add a new article, when an article is displayed, You can query the database based on the boardid to display relevant articles.
Fields in Table articles include id, boardid, title, content, author, and addtime. Copy codeThe Code is as follows: <! -- Program start -->
'Define A thenext function to find the ID of the next record. If the current record is already the last record, the output text is "no"
<%
Function thenext
Newrs = server. CreateObject ("adodb. recordset ")
SQL = "select top 1 * from articles where id>" & a1 & "order by id"
Set newrs1_conn.exe cute (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 next record ID. If the current record is already the first record, the output text is "no"
<%
Function thehead
Headrs = server. CreateObject ("adodb. recordset ")
SQL = "select top 1 * from articles where id <" & a1 & "order by id desc"
Set headrs1_conn.exe cute (SQL)
If headrs. eof then
Response. Write ("no ")
Else
A0 = headrs ("id ")
Response. Write ("<a href = 'view. asp? Id = "& a0 &" '> previous article </a> ")
End if
End function
%>
'Database connection file
<! -- # Include file = "conn. asp" -->
'Get the passed ID and display the author and content of the article title.
<%
Id = request ("id ")
SQL = "select * from articles where id =" & id
Set rsw.conn.exe cute (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>
& Lt; td width = "576" align = "left" & gt;
<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"> <! -- Extract the database data and output the data after encoding to keep the input format unchanged --> <% = replace (server. HTMLEncode (rs ("content"), chr (13), "<br>") %> </span> </td>
</Tr>
<% A1 = rs ("id") %>
<Tr>
<Td width = "269" align = "right"> <! -- Call the previously defined function to display the previous one --> <% thehead %> </td>
<Td width = "257" align = "right"> <! -- Call the function defined above to display the next article --> <% thenext %> </td>
</Tr>
<% Rs. MoveNext %>
<% Loop %>
</Table> </td>
<Td width = "217" valign = "top" align = "left"> related articles:
'Locate the article of the same topic based on the topic number of the current article
<%
SQL = "select * from articles where boardid =" & boardid &""
Set rsw.conn.exe cute (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>
<! -- 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.