?? 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 + -