📄 newsdiscuss.asp
字号:
<!--#include file="ConnDB.asp"-->
<HTML>
<HEAD>
<title>我来说两句</title>
<link rel="stylesheet" href="style.css">
<script LANGUAGE="javascript">
// 打开新窗口
function newwin(url) {
var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=300,height=100")
newwin.focus()
return false;
}
</script>
</HEAD>
<BODY>
<%
'任何人都可以添加评论,如果不写姓名,则认为是匿名
'新闻翻页排序
Dim CurPage,PERPAGE
PERPAGE = 10
'读取页码参数page,如果page为空,则为第一页
If Request("page") = "" Then
CurPage = 1
Else
CurPage = CInt(Request("page"))
End If
'得到新闻编号,在表discuss中查找此新闻的评论,按时间先后显示
Dim newsid
newsid = Request.QueryString("id")
'判断操作标记,是否为添加评论
sOper = Request.QueryString("Oper")
If sOper = "add" Then
'添加评论到数据库表discuss
UserId = Request.Form("UserId")
If UserId = "" Then
UserId = "匿名"
End If
Content = Request.Form("content")
If Content = "" Then
Content = "--"
End If
'生成插入数据的SQL语句
sql = "INSERT INTO Discuss( UserId, Content, Posttime, NewsId) VALUES('" _
& UserId &"','" & Content & "','" & now() & "'," & newsid & ")"
Conn.Execute(sql)
End If
'判断是否有删除权限
Dim rs,rsNews
Set rs = Server.CreateObject("ADODB.RecordSet")
'取得新闻题目
Set rsNews = Server.CreateObject("ADODB.RecordSet")
Set rsNews = Conn.Execute("SELECT title FROM News WHERE id = " & newsid)
If Not rsNews.EOF Then
newsTitle = rsNews("title")
End If
rsNews.Close()
'读取指定新闻的所有评论
sqlString="SELECT * FROM Discuss WHERE NewsId=" & newsid & " ORDER BY Posttime"
rs.Open sqlString, conn, 1, 1
%>
<center><h4><font color="red"><B>评论新闻题目:<%=newsTitle%></B></font><h4></center>
<%
If rs.EOF Then
rs.Close
Response.Write "没有评论"
Else
%>
<p><table border="1" align="center" width="90%" bordercolorlight="#FFFFFF" bordercolordark="#000080" bordercolor="#FFFFFF"
style="word-spacing: 0; margin-top: 0; margin-bottom: 0" cellspacing="0" cellpadding="0">
<%
'分页显示评论内容
Dim i
'设置每页记录数
rs.PageSize = PERPAGE
'设置当前页码
rs.AbsolutePage = CurPage
For i = 1 To rs.PageSize
%>
<tr><td align=left bgcolor="#99CCFF" width="60%"><%=rs("UserId")%> <%=rs("Posttime")%></td>
<td align=right bgcolor="#99CCFF" width="40%">
<%
'如果是管理员Admin则可以删除此评论信息
If Session("UserName") = "Admin" Then
%>
<a href="DiscussDelt.asp?id=<%=rs("Id")%>" onclick="return newwin(this.href)">删除</a>
<% End If %>
</td>
</tr>
<tr><td colspan="2"><%=rs("Content")%></td></tr>
<%
rs.MoveNext()
'如果到达记录集结尾,则退出
If rs.EOF Then
i = i + 1
Exit For
End If
Next
%>
</table></p>
<%
'显示分页信息
Response.Write "<table align=center border=0 width='90%'><tr bgcolor=#ffffff><td>第"&cstr(CurPage)&"页/总"&cstr(rs.pagecount)&"页 本页"&cstr(i-1)&"条/总"&cstr(rs.recordcount)&"条"
If CurPage = 1 Then
Response.Write "首页 上一页 "
Else
Response.Write "<a href='newsDiscuss.asp?page=1&id=" + newsid + "'>首页</a> <a href='newsDiscuss.asp?page=" + cstr(CurPage-1) + "&id=" + newsid + "'>上一页</a> "
End If
If CurPage = rs.PageCount Then
Response.Write "下一页 尾页"
Else
Response.Write "<a href='newsDiscuss.asp?page=" + cstr(CurPage+1) + "&id=" + newsid + "'>下一页</a> <a href='newsDiscuss.asp?page=" + cstr(rs.pagecount) + "&id=" + newsid + "'>尾页</a>"
End If
%>
</td></tr></table></p>
<%
Rs.close
End If
%>
<form name="myform" action="newsDiscuss.asp?id=<%=newsid%>&Oper=add" method="post">
<table border="1" align="center" width="90%" bordercolorlight="#FFFFFF" bordercolordark="#000080" bordercolor="#FFFFFF"
style="word-spacing: 0; margin-top: 0; margin-bottom: 0" cellspacing="0" cellpadding="0">
<tr><td align="left" bgcolor="#99CCFF"> 用户名 <input type="text" size="40" name="userid"></td></tr>
<tr><td align="center"><textarea rows="5" name="content" cols="70" style="font-family: 宋体; font-size: 9pt"></textarea></td></tr>
</table>
<p align="center"><input type="submit" value=" 提 交 " name="sbok"></p>
</form>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -