?? searchresult.asp
字號:
<!--#include File="ConnDB.asp"-->
<html><head>
<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=650,height=550")
newwin.focus()
return false;
}
</script>
</head>
<body vlink="#1155AA" bgcolor="#FFFFFF"><center>
<%
'根據用戶名讀取用戶姓名
Function GetUserName(UserId)
Dim RsUser,sql
Set RsUser = Server.CreateObject("ADODB.RecordSet")
sql= "SELECT * FROM Users WHERE UserName='" & Trim(UserId) & "'"
Set rsUser = Conn.Execute(sql)
If NOT rsUser.EOF Then
GetUserName = rsUser("Ename")
Else
GetUserName = "無名"
End If
End Function
%>
<%
' 提取發布時間查詢范圍
sDate = Request("sdate")
eDate = Request("edate")
' 根據時間字段設置查詢語句,需要把時間字符串轉換為日期型
If Len(sDate)>0 And Len(eDate)>0 Then
strSqlPTime = " WHERE PostTime>='" & sDate & "'"
strSqlPTime = strSqlPTime & " And PostTime<='" & eDate & "'"
ElseIf Len(sDate)>0 And Len(eDate)=0 Then
strSqlPTime = " WHERE PostTime>='" & sDate & "'"
ElseIf Len(sDate)=0 And Len(eDate)>0 Then
strSqlPTime = " WHERE PostTime<='" & eDate & "'"
End If
' 取得查詢模式(精確查詢或模糊查詢),參見search.asp中的定義
searchcontent1 = Request("searchcontent")
fanwei = Request("fanwei")
If fanwei ="all" Then '精確查詢
searchcontent = searchcontent1
Else '模糊查詢
searchcontent = "%" & searchcontent1 & "%"
End If
' 取得查詢范圍值
searchfanwei = Request("D1")
If searchfanwei="title" Then '只在新聞標題中查詢
Response.Write "<h4><font color=#7966C6>按 信息標題 查詢的結果</font></h4><br>"
strSQL = " Title LIKE '" & searchcontent & "' ORDER BY PostTime DESC"
ElseIf searchfanwe="content" Then '只在新聞內容中查詢
Response.Write "<h4><font color=#7966C6>按 信息內容 查詢的結果</font></h4><br>"
strSQL = " Content LIKE '" & searchcontent1 & "' ORDER BY PostTime DESC"
End If
'合并查詢條件
If Len(strSqlPTime)=0 Then
strSQL = " WHERE " & strSQL
Else
strSQL = strSqlPTime & " And " & strSQL
End If
'記錄查找到的新聞序號
Dim ncnt
ncnt = 0
'輸出表格
Response.Write "<table width='100%'>"
Response.Write "<tr>"
Response.Write "<td align=middle width='10%'><b>序號</b></td>"
Response.Write "<td align=left width='30%'><b>信息標題</b></td>"
Response.Write "<td align=middle width='14%'><b>所屬類別</b></td>"
Response.Write "<td align=middle width='10%'><b>內容長度</b></td>"
Response.Write "<td align=middle width='16%'><b>提交人</b></td>"
Response.Write "<td align=middle width='20%'><b>提交時間</b></td>"
Response.Write "</tr>"
Dim rsSearch,rsCate
Set rsSearch= Server.CreateObject("ADODB.RecordSet")
Set rsCate = Server.CreateObject("ADODB.RecordSet")
'生成查詢語句
strSQL = "SELECT * FROM News " & strSQL
'Response.Write "sql :"& strSQL
rsSearch.Open strSQL, Conn, 1, 3
'依次處理查詢結果
Do While Not rsSearch.EOF
ncnt = ncnt + 1
Response.Write "<tr bgColor=Lavender style='COLOR:Purple;'>"
Response.Write "<td align=middle>"&ncnt&"</td>"
'輸出新聞標題及鏈接
Response.Write "<td><a href=NewsView.asp?id="&rsSearch("Id")&" onClick='return newwin(this.href)'>"&rsSearch("Title")&"</a>"
' 判斷是否有圖片
If rsSearch("attpic") Then
Response.Write "(附圖)"
End If
Response.Write "</td>"
' 取得信息分類名稱
sql = "SELECT * FROM Category WHERE CateId=" & rsSearch("CateId")
Set rsCate = Conn.Execute(sql)
If NOT rsCate.EOF Then
Response.Write "<td align=middle>"&rsCate("CateName")&"</td>"
End If
' 計算內容大小
If rsSearch("Content")="--" Then
nlength=0
Else
nlength = Len(rsSearch("Content"))
' 輸出內容大小、提交人姓名
Response.Write "<td align=middle>"&nlength&" Bytes</td>"
' 顯示提交人姓名
Response.Write "<td align=middle>"&GetUserName(rsSearch("Poster"))&"</td>"
' 顯示提交時間
Response.Write "<td align=middle>"&rsSearch("PostTime")&"</td>"
Response.Write "</tr>"
End If
rsSearch.MoveNext()
LOOP
Response.Write "</table>"
Set rsSearch = Nothing
Set rsCate = Nothing
Set Conn = Nothing
%>
</center>
<p align="center">
<input type="button" value=" 返 回 " LANGUAGE =javascript onclick="history.back()">
</p>
</body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -