标题: ASP ACCESS 数据高级搜索 By Stabx
正文:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/conn.asp" -->
<!--#include virtual="include/globalabbr.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<title><%=sitename_%></title>
<script LANGUAGE="JavaScript" TYPE="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<%
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' subject : ASP ACCESS 数据高级搜索
'
' author : Stabx<shawl.qiu@gmail.com>
'
' blog : http://blog.csdn.net/btbtd \ http://btbtd.exblog.jp/
'
' blog name : Phoenix.GI - P.GI
'
' date : 2006-5-5
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>
<!--#include virtual="include/top.asp"-->
<form ACTION="" METHOD="get" NAME="searchform" ID="searchform">
搜索:
<select NAME="searchoption" ID="searchoption">
<option VALUE="bytitle" <% if request("searchoption")="bytitle" then response.write "selected" end if%>> by title</option>
<option VALUE="bytag" <% if request("searchoption")="bytag" then response.write "selected" end if%>>by tag</option>
<option VALUE="bywriter" <% if request("searchoption")="bywriter" then response.write "selected" end if%>>by writer</option>
<option VALUE="bywww" <% if request("searchoption")="bywww" then response.write "selected" end if%>>by www</option>
</select>
<input NAME="findtext" TYPE="text" ID="findtext" <% if request("findtext")<>"" then response.write "value="&request("findtext") else response.Write "value=" end if%>>
<input TYPE="submit" NAME="Submit" VALUE="Submit">
<br>
精确:
<input NAME="findmode" TYPE="radio" VALUE="exacttrue" <% if request("findmode")="exacttrue" then response.write "CHECKED" end if%>>
:
是
<input NAME="findmode" TYPE="radio" VALUE="exactfalse" <% if request("findmode")<>"exacttrue" then response.write "CHECKED" end if%>>
: 否
<br>
顺序:
<input NAME="ordersc" TYPE="radio" VALUE="asc" <% if request("ordersc")="asc" then response.write "CHECKED" end if%>>
:升序
<input NAME="ordersc" TYPE="radio" VALUE="desc" <% if request("ordersc")<>"asc" then response.write "CHECKED" end if%>>
:降序
<br>
显示:
<input NAME="showarticles" TYPE="radio" VALUE="showtitle" <% if request("ordersc")="asc" or (request("ordersc")<>"showcontent" and request("ordersc")<>"titleandcontent") then response.write "CHECKED" end if%>>
:标题
<input NAME="showarticles" TYPE="radio" VALUE="titleandcontent" <% if request("showarticles")="titleandcontent" then response.write "CHECKED" end if%>>
:标题+内容
<br>
排序:
<input NAME="orderby" TYPE="checkbox" ID="orderby" VALUE="article.articleid" <% if join(filter(split(replace((request("orderby")),","," ")),"article.articleid"))="article.articleid" then
response.write "CHECKED"
elseif request("orderby")="" and request("searchoption")<>"bytag" then response.Write "checked" end if%>>
:文章ID
<input NAME="orderby" TYPE="checkbox" ID="orderby" VALUE="hits" <% if join(filter(split(replace((request("orderby")),","," ")),"hits"))="hits" then response.write "CHECKED" end if%>>
:点击
<input NAME="orderby" TYPE="checkbox" ID="orderby" VALUE="dateandtime" <% if join(filter(split(replace((request("orderby")),","," ")),"dateandtime"))="dateandtime" then response.write "CHECKED" end if%>>
:日期
<input NAME="orderby" TYPE="checkbox" ID="orderby" VALUE="classid" <% if join(filter(split(replace((request("orderby")),","," ")),"classid"))="classid" then response.write "CHECKED" end if%>>
:大类
<input NAME="orderby" TYPE="checkbox" ID="orderby" VALUE="nclassid" <% if join(filter(split(replace((request("orderby")),","," ")),"nclassid"))="nclassid" then response.write "CHECKED" end if%>>
:子类
</form>
<% if isempty(request("searchoption")) or isempty(request("findtext")) or request("findtext")="" and isempty(request("tag")) then
response.Write searchError_ %>
<% else %>
<% if len(request("findtext"))<=1 then
response.Write searchKeyless2_
else %>
<%
set rsFindSearchKey=server.CreateObject("adodb.recordset")
rsFindSearchKey.open "select * from search order by searchid desc ", MM_conn_String
RPP=50 '设置每页显示数目
I=1 '设置循环开始数目
showNumberLink_=10
toPage_="?searchoption="&request("searchoption")&"&findtext="&request("findtext")&"&findmode="&request("findmode")&"&ordersc="&request("ordersc")&"&showarticles="&request("showarticles")&"&pageview="
nonLinkColor_="#CCCCCC"
if request("searchoption")<>"" and request("searchoption")="bytitle" and request("searchoption")<>"bytag" and request("searchoption")<>"bywriter" and request("searchoption")<>"bywww" then
searchoption_="title"
elseif request("searchoption")<>"" and request("searchoption")<>"bytitle" and request("searchoption")="bytag" and request("searchoption")<>"bywriter" and request("searchoption")<>"bywww" then
searchoption_="tag"
elseif request("searchoption")<>"" and request("searchoption")<>"bytitle" and request("searchoption")<>"bytag" and request("searchoption")="bywriter" and request("searchoption")<>"bywww" then
searchoption_="writer"
elseif request("searchoption")<>"" and request("searchoption")<>"bytitle" and request("searchoption")<>"bytag" and request("searchoption")<>"bywriter" and request("searchoption")="bywww" then
searchoption_="www"
end if
if not isempty(request("ordersc")) and request("ordersc")<>"" and request("ordersc")="desc" then
sc_=request("ordersc")
else
sc_="asc"
end if
if not isempty(request("findmode")) and request("findmode")<>"" and request("findmode")="exacttrue" then
findtext_=ltrim(request("findtext"))
else
findtext_="%"&trim(request("findtext"))&"%"
end if
if isempty(request("orderby")) then
orderby_="article.articleid"
else
orderby_=request("orderby")
end if
Set rs = Server.CreateObject("ADODB.Recordset") '建立一个 rs 数据库查询
rs.CursorType = 1 '游标属性
rs.CursorLocation = 2 '游标位置
rs.LockType = 1 '定义数据库查询模式
if request("searchoption")="bytitle" or request("searchoption")="bywriter" or request("searchoption")="bywww" then
rs.open "select article.* from article where "&searchoption_&" like '"&findtext_&"' order by "&orderby_&" "&sc_,MM_conn_String
else
rs.open "select article.*,tag.* from article,tag where article.articleid=tag.articleid and "&searchoption_&" like '"&findtext_&"' order by "&orderby_&" "&sc_,MM_conn_String
end if
%>
<div CLASS="center"><% call fPageCount(RPP,rs,I,showNumberLink_,toPage_,nonLinkColor_)%></div>
<%
if rs.eof or rs.bof then
else
for i=1 to rpp
'替换查询关键字为高亮显示
titlereplacehl_=replace(rs("title"),request("findtext"),"<b class=b16>"&request("findtext")&"</b>",1,-1,1)
contentplacehl_=replace(rs("content"),request("findtext"),"<b class=b16>"&request("findtext")&"</b>",1,-1,1)
'第四个参数指定字符替换起始位置, 第五个指定每一个都要被替换, 第六个批定不区分大小写
if request("searchoption")="bytitle" or request("searchoption")="bywriter" or request("searchoption")="bywww" then
if isempty(request("showarticles")) or request("showarticles")="" then
showarticles_="<a HREF="&a1_&rs("classid")&a2_&rs("nclassid")&a3_&rs("articleid")&"#anchor TARGET=_blank>"&titlereplacehl_&"</a>"
elseif request("showarticles")<>"" and request("showarticles")="showtitle" then
showarticles_="<a HREF="&a1_&rs("classid")&a2_&rs("nclassid")&a3_&rs("articleid")&"#anchor TARGET=_blank>"&titlereplacehl_&"</a>"
elseif request("showarticles")<>"" and request("showarticles")="titleandcontent" then
showarticles_="<a HREF="&a1_&rs("classid")&a2_&rs("nclassid")&a3_&rs("articleid")&"#anchor TARGET=_blank>"&titlereplacehl_&"</a><br/>"&contentplacehl_
end if
else
if isempty(request("showarticles")) or request("showarticles")="" then
showarticles_="<a HREF="&a1_&rs("classid")&a2_&rs("nclassid")&a3_&rs("article.articleid")&"#anchor TARGET=_blank>"&titlereplacehl_&"</a>"
elseif request("showarticles")<>"" and request("showarticles")="showtitle" then
showarticles_="<a HREF="&a1_&rs("classid")&a2_&rs("nclassid")&a3_&rs("article.articleid")&"#anchor TARGET=_blank>"&titlereplacehl_&"</a>"
elseif request("showarticles")<>"" and request("showarticles")="titleandcontent" then
showarticles_="<a HREF="&a1_&rs("classid")&a2_&rs("nclassid")&a3_&rs("article.articleid")&"#anchor TARGET=_blank>"&titlereplacehl_&"</a><br/>"&tagW_&rs("tag")&"<br/>"&contentplacehl_
end if
end if
if request("searchoption")="bywriter" then
subtitle_="<br/>"&author_&"<a href=mailto:"&rs("email")&">"&replace(rs("writer"),request("findtext"),"<b class=b16>"&request("findtext")&"</b>",1,-1,1)&"</a>"
elseif request("searchoption")="bywww" then
subtitle_="<br/>"&source_&"<a href="&rs("url")&">"&replace(rs("www"),request("findtext"),"<b class=b16>"&request("findtext")&"</b>",1,-1,1)&"</a>"
end if
%>
<div>
<div CLASS="floatRight">
[ <a HREF="<%=ddv_&rs("dateandtime")%>"><%=rs("dateandtime")%></a> ]
</div>
—— <%=showarticles_&subtitle_%>
<% if request("searchoption")="bytag" then
response.Write "<br/>"&tagW_
showtagItem_=replace(rs("tag"),","," ")
for each ti in SPLIT(showtagItem_)
response.Write "<a href="&t_&ti&"#anchor target=_blank>"&replace(ti,request("findtext"),"<b class=b16>"&request("findtext")&"</b>",1,-1,1)&"</a>"&" "
next
end if %>
</div>
</div>
<p/>
<%
rs.movenext
if rs.eof or rs.bof then exit for
next
end if
rs.close
set rs=nothing
%>
<%end if%>
<% end if %>
<!--#include file="include/bottom.asp"-->
</body>
</html>
update
发表日期: 2006-5-4