border =0 align="center" class="sft">| 论坛首页 > 搜索 |
<%
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), "")
String = Replace(String, CHR(10), "
")
FormatStr = String
End Function
If Request.QueryString("mode") = "doit" then
if Request.Form("forum")<>"" then
forum = Request.Form("forum")
else
forum = Request.QueryString("forum")
end if
if Request.Form("search")<>"" then
search = Request.Form("search")
else
search = Request.QueryString("search")
end if
if Request.Form("SearchDate")<>"" then
SearchDate = Request.Form("SearchDate")
else
SearchDate = Request.QueryString("SearchDate")
end if
if Request.Form("search_type")<>"" then
search_type = Request.Form("search_type")
else
search_type = Request.QueryString("search_type")
end if
if Request.Form("andor")<>"" then
andor = Request.Form("andor")
else
andor = Request.QueryString("andor")
end if
if search <> "" then
keywords = split(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 forum <> 0 then
StrSql = StrSql & "Forum.Forum_ID = " & forum & " and "
End If
StrSQL = StrSql & "("
if searchdate <> 0 then
dt = cint(searchdate)
StrSql = StrSql & "T_date > #" & dateadd("d", -dt, now) & "#) and ("
End if
cnt = 0
For Each word in keywords
if search_type="a" then
StrSql2 ="SELECT Member_id FROM Members WHERE M_Name = '" & word & "'"
Set rs2= my_conn.Execute(StrSql2)
if rs2.Bof or rs2.Eof then
Response.Write "
错误:用户'" & word & "'不存在!
"
StrSql =StrSql & "Topics.T_Originator = -1"
else
StrSql =StrSql & "Topics.T_Originator = " & rs2("member_id")
end if
end if
if search_type="r" then
StrSql2 ="SELECT Member_id FROM Members WHERE M_Name = '" & word & "'"
Set rs2= my_conn.Execute(StrSql2)
if rs2.Bof or rs2.Eof then
Response.Write "错误:用户'" & word & "'不存在!
"
StrSql =StrSql & "(Topics.T_Originator = -1 or R_Posted_By = -1)"
else
StrSql =StrSql & "(Topics.T_Originator = " & rs2("member_id") & " or R_Posted_By = " & rs2("member_id") & ")"
end if
end if
if search_type="s" then
StrSql =StrSql & "Topics.T_Subject Like '%" & word & "%'"
end if
if search_type="m" then
StrSql =StrSql & "Topics.T_Subject Like '%" & word & "%' or Reply.R_Message Like '%"
StrSql =StrSql & word & "%' or Topics.T_Message Like '%"
StrSql =StrSql & word & "%' "
end if
if cnt < keycnt then StrSql = StrSql & andor
cnt = cnt + 1
next
StrSql =StrSql & ") order by topics.topic_id"
set rs = server.CreateObject("ADODB.RecordSet")
rs.Open strSql, my_conn, 1, 1
'Set rs= my_conn.Execute(StrSql)
If rs.Eof or rs.Bof then
Response.Write "抱歉,没有找到相关内容."
Else
%>
border="0" width=<%=TableWidth%> cellspacing="1" cellpadding="3" class="sft" style='TABLE-LAYOUT: fixed'>
| 帖子名称 |
所在论坛 |
发表时间 |
<%
rs.PageSize = ForumRow
PageSize = rs.PageSize
TotalPages=rs.PageCount
page=Request.QueryString("page")
if not IsNumeric(page) then page=1
if page>1 then
page = cint(page)
else
page = 1
end if
if page>TotalPages then page=TotalPages
rs.AbsolutePage=page
do until rs.Eof or RowCount>= PageSize
if not(id = rs("topic_id")) then
Response.Write ""
Response.Write rs("T_Subject") & " | "
Response.Write "" & rs("F_Name") &" | "
Response.Write "" & rs("T_Date") & " | "
Response.Write ""
End if
id = rs("topic_id")
RowCount= RowCount+ 1
rs.MoveNext
loop
%>
cellspacing="1" cellpadding="3" class="sft">
|
<%
Response.Write "共" & TotalPages & "页"
beginpage=1
endpage=Totalpages
if TotalPages>=5 then
if page>=3 then
beginpage=page-2
if page<=(TotalPages-2) then
endpage=page+2
else
endpage=TotalPages
beginpage=TotalPages-4
end if
else
beginpage=1
endpage=5
end if
end if
if beginpage>1 then response.write " <<"
for i=beginpage to endpage
if i=page then
response.write " "&i&""
else
response.write " "&i&""
end if
next
if endpage>>"
%>
|
<%
end if
else
Response.Write "请输入关键字"
Response.End
End if
Else
%>
<% End If
on error resume next
set rs = nothing
set rs2 = nothing
my_conn.Close
set my_conn = nothing
%>