日期:2014-05-16 浏览次数:21175 次
<%
dim rs,keyword,keywordlist,path,sql '定义变量
sql=""
keyword=Request.QueryString("keyword")
if keyword="" then
response.write "<Script>window.alert('请输入关键词!');history.back();</Script>"
else
keyword = replace(keyword,"'"," ") '用空格替换关键词中的字符"'"
keyword = replace(keyword,"["," ")
keyword = replace(keyword,"]"," ")
keyword = replace(keyword,","," ")
keyword = replace(keyword,","," ")
keyword=ltrim(rtrim(keyword)) '去掉关键词左边和右边的空格。函数LTrim去掉字符串左边空格,函数RTrim去掉字符串右边空格
keywordlist=split(keyword) '将用户输入的关键词用空格分成多个关键词并保存在一维数组keywordlist中
path=Request.QueryString("path") '使用Request对象的QueryString方法读取path值
sort_path="/"&Request.QueryString("path")&"/"
set rs=server.createobject("adodb.recordset") '建立RecordSet对象
for i=0 to ubound(keywordlist) 'ubound 函数获得数组最大下标值
keywordlist(i) = Trim(keywordlist(i)) 'Trim 函数去掉字符串左边和右边函数
sql=sql &" swy_list.swy_name like '%" & keywordlist(i) & "%' or " 'sql 语句,web.title 指的是数据表web中title列的值,web.title 中包含关键词keywordlist(i)
sql=sql &" swy_list.swy_info like '%" & keywordlist(i) & "%' or "
next
sql=Left(sql,(LEN(sql)-3))
'LEN 函数获得字符串的长度,left 函数获得字符串从左边数指定数目的字符,在此是去掉字符串中最后几位的"or "
'从数据库中查询满足条件的记录,并保存在rs 中
rs.open "select swy_name,swy_info from swy_list where "&sql,conn,1,1
%>
for i=0 to ubound(keywordlist) 'ubound 函数获得数组最大下标值
keywordlist(i) = Trim(keywordlist(i)) 'Trim 函数去掉字符串左边和右边函数
sql=sql &" swy_list.swy_name like '%" & keywordlist(i) & "%' or " 'sql 语句,web.title 指的是数据表web中title列的值,web.title 中包含关键词keywordlist(i)
sql=sql &" swy_list.swy_info like '%" & keywordlist(i) & "%' or "
&nb