⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.asp

📁 本程序开发的是一个论坛系统
💻 ASP
字号:
<!--#INCLUDE FILE="config.inc" -->
<!--#INCLUDE FILE="top.inc" -->

<%
set my_conn= Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
my_Conn.Open ConnString


Function FormatStr(String)
	on Error resume next
	String = Replace(String, CHR(13), "")
	String = Replace(String, CHR(10) & CHR(10), "</P><P>")
	String = Replace(String, CHR(10), "<BR>")
	FormatStr = String
End Function

If Request.QueryString("mode") = "doit" then

if Request.Form("search") <> "" then

'  Build Nightmare SQL Statement  - Kill Server!!!
keywords = split(Request.Form("search"), " ")
keycnt = ubound(keywords)

StrSql ="SELECT  Forum.*, Reply.*, Topics.* FROM (Forum LEFT JOIN Topics "
StrSql = StrSQl & "ON Forum.Forum_ID = Topics.Forum_id) LEFT JOIN Reply ON Topics.Topic_ID = Reply.Topic_ID "
StrSQl = StrSql & "WHERE "

if Request.Form("forum") <> 0 then
	StrSql = StrSql & "Forum.Forum_ID = " & Request.Form("forum") & " and "
End If

StrSQL = StrSql & "("

if Request.Form("searchdate") <> 0 then
	dt = cint(Request.Form("searchdate"))
	StrSql = StrSql & "T_date > #" & dateadd("d", -dt, now) & "#) and ("
End if
cnt = 0
For Each word in keywords
	StrSql =StrSql & "Forum.F_Description Like '%" & word & "%'  or Reply.R_Message Like '%"
	StrSql =StrSql & word & "%'  or  Topics.T_Message Like '%" 
	StrSql =StrSql & word & "%' "
	if cnt < keycnt then StrSql = StrSql &  Request.Form("andor") 
	cnt = cnt + 1
next 

StrSql =StrSql & ") order by topics.topic_id"

mypage=request("whichpage")
If mypage="" then
mypage=1
end if

rs.Open StrSql, my_Conn, 3,1

If rs.Eof or rs.Bof then  ' No categories found in DB
	Response.Write "<font face='" & DefaultFontFace & "'>No matches found</font>"
Else

%>



<table border="0" width="95%" cellspacing="2" cellpadding="0">
  <tr>
    
    <td align="center" bgcolor="<% =HeadCellColor %>"><strong><font face="<% =DefaultFontFace %>" size="2" color="<% =HeadFontColor %>">Topic</font></strong></td>
    <td align="center" bgcolor="<% =HeadCellColor %>"><strong><font face="<% =DefaultFontFace %>" size="2" color="<% =HeadFontColor %>">date</font></strong></td>
    <td align="center" bgcolor="<% =HeadCellColor %>"><strong><font face="<% =DefaultFontFace %>" size="2" color="<% =HeadFontColor %>">Forum</font></strong></td></tr>

<%
	
	   rec_id=""
	   do until rs.Eof '## Display Forum
	      if rec_id = rs("topic_id") then
			'  Don't do anything
		  Else
			Response.Write "<td bgcolor='" & ForumCellColor & "'><a href='Topic.asp?topic_id=" & rs("Topic_ID") & "&forum_id=" & rs("forum_id") & "&Topic_Title=" & server.URLEncode(left(server.URLEncode(rs("T_Subject")), 50)) & "&forum_title=" & server.URLEncode(rs("f_name")) & "'>"
			Response.Write "<font color='" & ForumLinkColor & "' face='" & DefaultFontFace & "' size='2'>" & rs("T_Subject") & "</a></td>"
			Response.Write "<td bgcolor='" & ForumCellColor & "' align='left' valign='top'><font color='" & ForumFontColor & "' face='" & DefaultFontFace & "' size='2'>" & rs("T_date") &  "</td>"
			Response.Write "<td bgcolor='" & ForumCellColor & "' align='left' valign='top'><font color='" & ForumFontColor & "' face='" & DefaultFontFace & "' size='2'>" & rs("F_Name") & "</td>"
			Response.Write "</tr>"
		  End if 
		  rec_id = rs("topic_id")
		  rs.MoveNext
		loop
%>
  </table>    
  <p align=center><font face="<% =DefaultFontFace %>" size=2><a href="javascript:history.go(-2)">Back To Forum</a>
<%
End If
Else ' Search = ""
%>
<font face="<% =DefaultFontFace %>" size='4'><center>You must enter keywords</center>
<p align=center><font face="<% =DefaultFontFace %>" size=2>
<a href="javascript:history.go(-2)">Back To Forum</a>
<%
Response.End
End if ' Search = ""
Else
%>
<div align="center"><center>

<form action="Search.asp?mode=doit" method="post">
<br>

<table border="0" width="80%" cellspacing="2" cellpadding="0">
<tr>
	<td bgcolor="#f7f7f7" align="right" valign=top width="50%">
		<font face="<% =DefaultFontFace %>" size='2'>Search For : 
	</td>
	<td bgcolor="#f7f7f7" align="left" valign=top width="50%">
		<font face="<% =DefaultFontFace %>" size='2'>
		<input type="text" name="search" size="34"><br>
		<input type="radio" name="andor" value=" and " checked>
		Search for all Words<br>
		<input type="radio" name="andor" value=" or ">
		Match any of the words
		</font>
	</td>
</tr>
<tr>
	<td bgcolor="#f7f7f7" align="right" valign=top width="50%">
		<font face="<% =DefaultFontFace %>" size='2'>Search Forum : 
	</td>
	<td bgcolor="#f7f7f7" align="left" valign=top width="50%">
		<font face="<% =DefaultFontFace %>">
		<select name="forum" size="1">
		<option value="0">All Forums
		<%
		StrSql = "SELECT * FROM Forum"
		set rs = my_conn.execute (strSql)
		On Error Resume Next
		do until rs.eof
			Response.Write "<option value=""" & rs("forum_id") & """>" & left(rs("F_name"), 40) & "</option>" & vbcrlf
		rs.movenext
		loop
		%>  
		</select></font>
	</td>
</tr>
	<td bgcolor="#f7f7f7" align="right" valign=top width="50%">
		<font face="<% =DefaultFontFace %>" size='2'>Search By Date : 
	</td>
	<td bgcolor="#f7f7f7" align="left" valign=top width="50%">
		<font face="<% =DefaultFontFace %>">
		<SELECT NAME="SearchDate">
		<OPTION value="0">Any Date
		<OPTION VALUE="1">Since Yesterday
		<OPTION VALUE="5">Since 5 Days Ago
		<OPTION VALUE="10">Since 10 Days Ago
		<OPTION VALUE="30">Since 30 Days Ago
		</SELECT>
	</td>
</tr>
</table>

<input type="submit" value="Search">
</form>
</center>
<% End If
on error resume next
set rs = nothing
my_conn.Close
set my_conn = nothing
 %>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -