Use ASP to create a website forum DIY (ii)

Source: Internet
Author: User
2, the construction article display module

As I said before, a specific article is divided between the Kanban and the subject. Therefore, it is possible to get a list of articles under a specific topic by displaying the articles through both the Kanban list and the main list.

(1) Board list display page:


html>
head>
title> Kanban List/title>
"Meta http-equiv=" Content-type "content=" text/html; charset=gb2312 ">
/head>

(2) Open the connection, display the Kanban list


The%set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "Driver={microsoft accessdriver (*.mdb)};d bq=" & Server.MapPath ("Bbssystem.mdb")
sql = "SELECT * FROM Kanban list"
Set Rs=conn.execute (SQL)
%>

Note: A simple SQL query that passes all Kanban-related messages back to the recordset Rs. The following task is to display the record and remember the content, and set up a connection to display the Kanban theme on the corresponding Kanban name.


Body bgcolor= "#FFFFFF"
H2 align= "Center" > kanban list
Table width= "60%" border= "0" cellspacing= "0" cellpadding= "0" align= "center"
TR bgcolor= "#FFFFCC"
TD height= "Width=" "25%" > Kanban name
TD height= "Width=" "21%" > board main
"TD height=" Width= "23%" "The number of topics
TD height= "Width=" "31%" > board main landing
/tr>

Note: Here is a section that shows the title of each column in the table, where I do not use a uniform function to display the contents of Rs records, because it can be more control of the appearance and style of the table, although it is a bit cumbersome to use, but more flexible.


%
Todo
BOARDID=RS ("id")
Boardname=rs ("name")
Boardmanager=rs ("board Master")
Response.Write "tr>< td>"

Note: This line is the focus, and when clicked on the name of each board, you can connect to the page that displays the Kanban theme. The program code looks a bit cumbersome, I break it down for you, and you'll understand. After clicking, the browser requests a qboard.asp page with a parameter boardid representing the ID number of the Kanban to display, and a question mark (?) between the request page and the parameters. Separated Boardid is the previously set variable, which contains the ID number of the corresponding kanban. This connection is also accompanied by another parameter boardname, which is used to pass the Kanban name to the qboard.asp page. Use "&" between multiple parameters to separate. This parameter is not required and is passed in order to avoid querying the Kanban name again with Boardid in the qborad.asp. In general, the ability to use less database operations should be as small as possible, which can improve the performance of ASP pages. Because the Response.Write statement uses a string as a parameter, the above string and variable use the "&" join character. The final ASP page explain the result should be like this


The a href=qboard.asp?boardid=1&boardname= system board system board is/a>< td>.
Response.Write "td>< a href=qauthor.asp?author=" &boardmanager & ">" &boardmanager & "/a> "
Response.Write "td>" &rs ("Subject number") & "/td>"
Response.Write "td>< a href=managerlogin.asp?boardid=" &boardid & "> board processing"/a> /tr> "

Note: In this table, in addition to being able to display the content of the Kanban subject by the connection, there is also a bamboo query part and the board processing part, the moderator query can be realized through the qauthor.asp, it simply extracts the author's message from the database, and displays it, here is not much to say. and the board processing is handled by the managerlogin.asp page. This belongs to the article review module, I'll elaborate later.


Rs.movenext
Loop until rs.eof
%>

Note: All the messages in the recordset are displayed through a do ... loop loop.


/table>
Div align= "center" >

Click on the kanban name to get a list of topics, click on the board main name can see the main message


/div>
/body>
/html>
%
Set rs=nothing
Conn.close
Set conn=nothing
%>

(3) Create qbaord.asp page:


%
Boardid=request ("Boardid") ' takes out the Kanban ID number passed over from the previous page
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "Driver={microsoft accessdriver (*.mdb)};d bq=" & Server.MapPath ("Bbssystem.mdb")
Set cmd = Server.CreateObject ("Adodb.command")
Set cmd. ActiveConnection = conn
Cmd.commandtext = "topic list"
ReDim param (0)//NOTE: Declare parameter array
Param (0) = CLng (Boardid)//NOTE: CLng can not be ignored
Set rs = cmd. Execute (, param)
%>
html>
head>
title> Topic list/title>
"Meta http-equiv=" Content-type "content=" text/html; charset=gb2312 ">
/head>
Body bgcolor= "#FFFFFF"
H1 align= "center" ><%=rs ("Kanban name")%> Board topic list Table width= "80%" border= "0" cellspacing= "0" cellpadding= "0" align= "center"
TR bgcolor= "#FFFFCC"
TD width= "89%" height= "21" > theme </td>
TD width= "11%" height= "21" > Number of articles </td>
/tr>
%
Todo
TOPICID=RS ("id")
Topicname=rs ("title")
Sum=rs ("Number of articles")
Response.Write "tr>< td><a href=qtopic.asp?topicid=" & topicid& "&boardname=" & boardname& "" ; Topicname & "/a></td>"
Response.Write "td>" &sum & "/td></tr>"
Rs.movenext
Loop until rs.eof
%>
/table>
/body>
/html>

Note: qboard.asp lists all the topics under a certain layout, and after clicking on the topic name, it goes to the appropriate topic list. This list is implemented by qtopic.asp, an ASP script. Qtopic.asp's program code is virtually indistinguishable from qboard.asp in nature, but differs in its own details, and is not intended to be spoken.

(4) After clicked the article title in the article List, will enter the article content browsing page article.asp:


%
Articleid=request ("ArticleID")
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "Driver={microsoft accessdriver (*.mdb)};d bq=" & Server.MapPath ("Bbssystem.mdb")
Set cmd = Server.CreateObject ("Adodb.command")
Set cmd. ActiveConnection = conn
Cmd.commandtext = "Query article by ID"
ReDim param (0) ' statement
Param (0) = CLng (ArticleID) ' Cint cannot be ignored
Set rs = cmd. Execute (, param)
Author=rs ("Author id")
Title=rs ("title")
Data=rs ("date")
Rate=rs ("recommended degree")
Boardid=rs ("Kanban id")
Topicid=rs ("Subject ID")
Boardname=rs ("Kanban name")
Topicname=rs ("Subject name")
Content=rs ("content")
Content=replace (Content,vbcrlf, "

p>")
Content= "p>" & content& "/p>"

Note: This is a place to note that the Content field contains text for the memo type, which can contain newline characters. In the HTML display, you must replace the newline character (that is, the vbCrLf constant) with the HTML paragraph symbol. This will not disrupt the formatting of the original input when the paragraph and paragraph are connected. If you want to design better, you can use CSS to reset the meaning of the p> tag, set its test-indent properties, you can achieve the beginning of each paragraph of space.

(5) Add the number of clicks to a


Sql= "Update content table Set Click count = click Times +1where id=" & ArticleID
Conn.execute SQL

Note: Here is an SQL statement, not when the page is displayed, the corresponding table will be clicked on the number of times to add one, so that the number of articles to browse the statistics, and can be ranked in order. When I execute the statement, I find that the embedded variable name should be enclosed in a single quotation mark in the SQL statement, but I do not have a single quotation mark on the ArticleID variable here, and I am able to pass it, and I have always written this as an error. I don't know if it's because of the new version of ADO.


Set cmd=nothing
%>
html>
head>
title>untitled document</title>
"Meta http-equiv=" Content-type "content=" text/html; charset=gb2312 ">
/head>
Body bgcolor= "#E9E9E4"
Table width= "89%" border= "0" cellspacing= "0" cellpadding= "0" align= "center"
TR bgcolor= "#CCCCCC"
td> Author: Font color= "#FF3366" ><a href= "qauthor.asp?author=<%=author%>" ><%=author%> (/a></font>) Date of publication: "Font color=" #FF 3333 "> <%=data%>/font>
Kanban: Font color= "#FF3333" ><a href= "qboard.asp?boardid=<%=boardid%>" ><%=boardname%></a></font> Board main recommended: "Font color=" # FF3333 "> #rate # </font>/td>
/tr>
TR bgcolor= "#CCCCCC"
td> title: Font color= "#FF3333" > <%=title%>
Subject: "A href=" qtopic.asp?topicid= <%=topicid%> ">%=topicname%></a>/font><
/tr>
TR valign= "Top"
td>
hr>
Font color= "#FF3366" > article content:/font>< br>
br>
Font color=blue><%response.writecontent%></font>
br>
br>
/td>
/tr>
TR valign= "Top"
TD height= "18"
Table width= "50%" border= "0" cellspacing= "0" cellpadding= "0" align= "right" bgcolor= "#CCCCCC"
tr>
TD width= "0%" "/td>
<TD width= "65%" > about this topic <a Href= "submit.asp?topicid=<%=topicid%>&boardid= <%=boardid%>" > comment on/a> </td>

This connection allows users to express their views on the topic of this comment, which is what the next module is going to tell you, and click here.


/tr>
/table>
/td>
/tr>
/table>
/body>
/html>
%
Set rs=nothing
Conn.close
Set conn=nothing
%>

To this end, the article shows that the section is completed. Let's take a look at how the article published is implemented.




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.