asp多字段模糊搜索的函数
2023-06-13 09:13:41 时间
比较简单直接的sql语句
Recordset1.Source="SELECT*FROM表WHERE字段LIKE"%"+Replace(Recordset1__MMColParam,""","""")+"%"or字段2like"%"+Replace(Recordset1__MMColParam,""","""")+"%"ORDERBYidDESC" Recordset1.Source="SELECT*FROM表WHERE字段LIKE"%"+Replace(Recordset1__MMColParam,""","""")+"%"and字段2=2ORDERBYidDESC"
下面是一些补充
函数名:keyword_sousuo
作用:生成sql查询条件
参数:table_field------表的字段名(之间用逗号分开)
keyword------搜索关键词(之间用空格分开)
返回:sql查询条件
核心代码
"================================================== "函数名:keyword_sousuo "作用:生成sql查询条件 "参数:table_field------表的字段名(之间用逗号分开) "keyword------搜索关键词(之间用空格分开) "返回:sql查询条件 "================================================== functionkeyword_sousuo(byvaltable_field,byvalkeyword) dimstr01,str02,keywords,table_fields,i,j table_fields=split(trim(table_field),",") keywords=split(trim(keyword),",") iftable_field<>""then str01="("&table_fields(0)&"like"%"&keyword&"%"" forj=0toubound(table_fields) str01=str01&"or"&table_fields(j)&"like"%"&keyword&"%"" next str01=str01&")" else response.Write("<script>alert("参数错误(不能为空)!")</script>") response.End() endif "全角--》半角 空格 "keyword=replace(keyword," ","") "whileInStr(keyword,"")>0 "keyword=replace(keyword,"","") "wend keywords=split(keyword,"") ifubound(keywords)>0then fori=0toubound(keywords) str02=str02&"("&table_fields(0)&"like"%"&keywords(i)&"%"" forj=1toubound(table_fields) str02=str02&"or"&table_fields(j)&"like"%"&keywords(i)&"%"" next str02=str02&")" next str02="("&replace(str02,")(",")and(")&")" keyword_sousuo="("&str01&"or"&str02&")" else keyword_sousuo=str01 endif endfunction "================================================== "函数名:keyword_tag "作用:将字符串里的关键词标记为红色 "参数:str------字符串 "keyword------标记关键词(之间用空格分开) "返回:字符串(html格式) "================================================== functionkeyword_tag(byvalstr,byvalkeyword) dimkeywords,str01,str02,i "全角--》半角 空格 "keyword=replace(keyword," ","") "whileInStr(keyword,"")>0 "keyword=replace(keyword,"","") "wend str01=replace(str,keyword,"<fontcolor=""#ff0000"">"&keyword&"</font>") keywords=split(keyword,"") ifubound(keywords)>0then str02=str fori=0toubound(keywords) str02=replace(str02,keywords(i),"<fontcolor=""#ff0000"">"&keywords(i)&"</font>") next keyword_tag=str02 else keyword_tag=str01 endif endfunction 以下是一个例子http://www.zhouhaihe.com/blog/uploads/200604/recordread.asp <%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%> <% optionexplicit dimconn,connstr,database connstr="DBQ="+server.mappath("record.mdb")+";DefaultDir=;DRIVER={MicrosoftAccessDriver(*.mdb)};" setconn=server.CreateObject("adodb.connection") conn.openconnstr dimn,rs,page,keyword,keywords,RecordCount,pageCount,pos,i,sql_where n=50 page=Request("page") keyword=trim(request("keyword")) sql_where=keyword_sousuo("title,cz,name,time",keyword) setrs=server.CreateObject("adodb.recordset") rs.open"select*fromrecordwhere"&sql_where&"orderbyiddesc",conn,1,2 ifpage=0then page=1 endif RecordCount=0 dowhilenotrs.Eof RecordCount=RecordCount+1 rs.MoveNext loop ifnotRecordCount=0then rs.MoveFirst endif pageCount=RecordCount/n pageCount=int(pageCount) if(RecordCountmodn)>0then PageCount=PageCount+1 endif %> <styletype="text/css"> <!-- .STYLE3{color:#666666} --> </style> <tablewidth="100%"border="0"cellspacing="0"cellpadding="0"> <formid="form1"name="form1"method="post"action="?"><tr><tdalign="center"><inputname="keyword"type="text"id="keyword"value="<%=keyword%>"size="30"/> <inputtype="submit"name="Submit"value="搜索"/> <spanclass="STYLE3">(关键词之间用空格分开)</span></td> </tr></form> <tr> <tdheight="5"></td> </table> <tablewidth="600"border="1"align="center"cellpadding="4"> <tralign="center"> <tdwidth="131">标题</td> <tdwidth="131">动作</td> <tdwidth="131">用户名</td> <tdwidth="132">时间</td> </tr> <%pos=0 dowhilepos<(page-1)*n pos=pos+1 rs.moveNext loop i=0 whilenotrs.eofandi<n i=i+1%> <tralign="center"> <td><%=keyword_tag(rs("title"),keyword)%></td> <td><%=keyword_tag(rs("cz"),keyword)%></td> <td><%=keyword_tag(rs("name"),keyword)%></td> <td><%=keyword_tag(rs("time"),keyword)%></td> </tr> <%rs.movenext wend rs.close setrs=nothing conn.close setconn=nothing "================================================== "函数名:keyword_sousuo "作用:生成sql查询条件 "参数:table_field------表的字段名(之间用逗号分开) "keyword------搜索关键词(之间用空格分开) "返回:sql查询条件 "================================================== functionkeyword_sousuo(byvaltable_field,byvalkeyword) dimstr01,str02,keywords,table_fields,i,j table_fields=split(trim(table_field),",") keywords=split(trim(keyword),",") iftable_field<>""then str01="("&table_fields(0)&"like"%"&keyword&"%"" forj=0toubound(table_fields) str01=str01&"or"&table_fields(j)&"like"%"&keyword&"%"" next str01=str01&")" else response.Write("<script>alert("参数错误(不能为空)!")</script>") response.End() endif "全角--》半角 空格 keyword=replace(keyword," ","") "whileInStr(keyword,"")>0 "keyword=replace(keyword,"","") "wend keywords=split(keyword,"") ifubound(keywords)>0then fori=0toubound(keywords) str02=str02&"("&table_fields(0)&"like"%"&keywords(i)&"%"" forj=1toubound(table_fields) str02=str02&"or"&table_fields(j)&"like"%"&keywords(i)&"%"" next str02=str02&")" next str02="("&replace(str02,")(",")and(")&")" keyword_sousuo="("&str01&"or"&str02&")" else keyword_sousuo=str01 endif endfunction "================================================== "函数名:keyword_tag "作用:将字符串里的关键词标记为红色 "参数:str------字符串 "keyword------标记关键词(之间用空格分开) "返回:字符串(html格式) "================================================== functionkeyword_tag(byvalstr,byvalkeyword) dimkeywords,str01,str02,i "全角--》半角 空格 keyword=replace(keyword," ","") "whileInStr(keyword,"")>0 "keyword=replace(keyword,"","") "wend str01=replace(str,keyword,"<fontcolor=""#ff0000"">"&keyword&"</font>") keywords=split(keyword,"") ifubound(keywords)>0then str02=str fori=0toubound(keywords) str02=replace(str02,keywords(i),"<fontcolor=""#ff0000"">"&keywords(i)&"</font>") next keyword_tag=str02 else keyword_tag=str01 endif endfunction dimy %><tralign="center"> <tdcolspan="4"><%=RecordCount%>个 <fontcolor="#FF0000"><%=page%></font>/<%=pageCount%>页 <%=n%>个/页转到: <SELECTname="select"onchange=window.open(this.options[selectedIndex].value,"_self")> <%y=1 dowhiley<pagecount+1%> <OPTIONvalue=?page=<%=y%>&keyword=<%=server.URLEncode(keyword)%><%ifcstr(page)=cstr(y)thenresponse.Write("selected")endif%>>第<%=y%>页</OPTION> <%y=y+1 loop%> </SELECT></td> </tr> </table>
相关文章
- pycharm全文搜索_python搜索关键词
- python 爬虫 通过搜索引擎搜索好看的图片进行多线程高效率爬取(解决href关联问题)
- AI图像识别_头像搜索图片识别在线
- NLP技术在搜索推荐场景中的应用
- WPF使用AvalonEdit实现代码高亮显示、搜索、替换功能
- BeautifulSoup文档4-详细方法 | 用什么方法对文档树进行搜索?
- linux文件管理命令实例分析【权限、创建、删除、复制、移动、搜索等】
- SQLServer地址搜索性能优化
- 更新:已解除 | 微信疑似封杀必应搜索 内置浏览器加载必应显示被多人投诉
- Lynx在过去很长一段时间被认为是最好的浏览器,但是其巅峰时期已经过去了。这款基于文本的浏览器需要通过终端视窗查看,如果使用GUI服务器进行网络搜索,那么Lynx这类工具就必不可少了。不过它和标准浏览器不一样,不能点击链接,也不能看图片,当然更不用提Flash或Java小程序了。
- 如何使用C ASP实现MySQL数据库连接(c asp连接mysql)
- 使用ASP连接MySQL实现数据库应用(asp连接空间mysql)
- ASP程序连接MySQL完美实现本地数据库操作(asp连接mysql地址)
- ASP实现MySQL数据库连接及编写代码(asp连接mysql代码)
- ASP驱动MySQL简单快捷高效(asp调用mysql)
- ASP技术可以驱动MySQL吗(asp能连接mysql吗)
- 用 ASP 管理 MySQL 源码,轻松获取开发效率(asp管理mysql源码)
- ASP连接MySQL登录动态网站实战(asp 登录 mysql)
- 如何使用ASP添加MySQL引用(asp添加mysql引用)
- 错误ASP操作MySQL出现异常如何破解(asp取mysql出现)
- MySQL与ASP结合,为网站带来绿色发展(asp mysql 绿色)
- ASP操作Oracle6实现最佳数据库连接体验(asp连接oracle6)
- 从ASP学习如何写Oracle函数(asp如何写oracle)
- 结合asp和存储过程做的搜索程序
- javascript实现划词标记划词搜索功能修正版
- javascript页面划词搜索JS
- asp经典入门教程在ASP中使用SQL语句