比较不错的asp单表单字段多条件查询


用途:文章表内文章关键字查询
查询格式: 百度 google   百度好还是google好 百度+google (也可不输入条件全部查询)


<!--#include file="conn.asp"-->
<%
Function SearshSQL(Tname,Lname,Str) 'Tname-表名 Lname-列名 Str-查询的字符
If Trim(Str)="" then
MySql="Select * From "&Tname
Else
Str=SqlEncode(Str) '预处理查询字符串
ArrStr=split(Str," ") '用空格分割处理后字符串
Umax=Ubound(ArrStr) '分割后数组上维,确定分割成关键词的个数
If Umax>0 Then '关键词中多个空格的处理,从第2维开始处理
For i=1 to Umax
StrTemp=ArrStr(i)
If Trim(StrTemp)="" Then StrTemp="/~~~~~/" '分割成的元素为空用特殊字符代替
Sql=Sql &" Or "& Lname &" like '%"& StrTemp &"%'"
Next
End If

MySql="Select * From "& Tname &" where "& Lname &" like '%"&ArrStr(0)&"%'"&Sql

Do
j=InStr(1,MySql, "%/~~~~~/%",1)
If j=0 Then
Exit Do
End If
MySql=Replace(MySql," Or "&Lname&" like '%/~~~~~/%'","")
Loop
End IF


SearshSQL=MySql

end function

Function SqlEncode(Str) '格式化字符串
str=replace(str," "," ") '先把左右的全角空格替换成半角空格
str=trim(str)
str=replace(str,"["," ")
str=replace(str,"';"," ")
str=replace(str,"'"," ")
str=replace(str,"_"," ")
str=replace(str,"%"," ")
str=replace(str,"+"," ")
str=replace(str," "," ")
sqlencode=str
end function
%>
<%
sql=SearshSQL("article","coments","萝卜+白菜 狗熊") +"order by..(排序)"
Set rs=Server.Createobject("ADODB.RECORDSET")
rs.Open sql,conn,1,1
if not rs.eof then

下面的自己写



相关阅读:
详解Oracle中如何用非默认方式创建外键
加密Email地址的制作方法
帮助你好好学习CSS的“边”和“内容”
javascript表格随机排序代码
PHP中文汉字验证码
MySQL多表操作和备份处理
XHTML教程:针对初学者的XHTML基础
一个快速删除Oracle的好方法
注册或注销 Access 2007 中 ActiveX 控件
图片上传的数据库部分(自动生成所略图
Asp操作Xml的精炼类,含示例代码
第九节 绑定 [9]
CSS技巧:改善代码可读性并简化代码管理
一个初级的linux后门制作方法
快速导航

Copyright © 2016 phpStudy | 皖ICP备18014864号-4