主题:[讨论]复合查询,请大家帮帮忙!
样式:
<select name="types1" class="login" id="types1">
<option value="" selected="selected">类别</option>
<option value="title" >按标题</option>
<option value="content">按内容</option>
<option value="auther">按作者</option>
</select>
<input name="key2" type="text" class="login" id="key2" onclick="this.select()" value="请输入关键字" />
<select name="types" class="login" id="types">
<option value="" selected="selected">类别</option>
<option value="title" >按标题</option>
<option value="content">按内容</option>
<option value="auther">按作者</option>
</select>
<input name="key" type="text" class="login" id="key" onclick="this.select()" value="请输入关键字" />
<input type="submit" name="Submit" value="查找新闻" class="login" />
查询代码:
<%
Dim Key,Types,key2,types1
Key=Request("key")
Types=Request("Types")
key=request("key2")
types1=request("types1")
If (Key="" and key2="")Then
Response.Write "<script language='javascript'>alert('你的关键字不允许为空');location.href='Index.asp'</script>"
response.End()
end if
If (Types="title" and types1="content") then
Sql="select * from NewsInf where title like '%"&Key&"%' and content like '%"&Key2&"%'"
elseif (Types="content" and types1="title") then
Sql="select * from NewsInf where Content like '%"&Key&"%' and title like '%"&Key2&"%'"
elseif (Types="author" and types1="title") then
Sql="select * from NewsInf where author like '%"&Key&"%' and title like '%"&Key2&"%'"
elseif (Types="author" and types1="content") then
Sql="select * from NewsInf where author like '%"&Key&"%' and content like '%"&Key2&"%'"
elseif (Types="content" and types1="author") then
Sql="select * from NewsInf where content like '%"&Key&"%' and author like '%"&Key2&"%'"
elseif (Types="title" and types1="author") then
Sql="select * from NewsInf where title like '%"&Key&"%' and author like '%"&Key2&"%'"
elseif (Types="title" and types1="") then
Sql="select * from NewsInf where title like '%"&Key&"%'"
elseif (Types="" and types1="title") then
Sql="select * from NewsInf where title like '%"&Key2&"%'"
elseif (Types="author" and types1="") then
Sql="select * from NewsInf where author like '%"&Key&"%'"
elseif (Types="" and types1="author") then
Sql="select * from NewsInf where author like '%"&Key2&"%'"
elseif (Types="content" and types1="") then
Sql="select * from NewsInf where content like '%"&Key&"%'"
elseif (Types="" and types1="content") then
Sql="select * from NewsInf where content like '%"&Key2&"%'"
elseif (Types<>"" and types1<>"") then
Response.Write "<script language='javascript'>alert('如果只输入单个条件,请将一边留空');location.href='Index.asp'</script>"
response.End()
end if
Set Rs=Server.CreateObject("ADODB.Recordset")
Rs.Open Sql,conn,1,3
if not rs.eof then
i=1
do while not rs.eof
%>
代码没有语言错误,就是查询不对,请大家帮着改改,谢谢
<select name="types1" class="login" id="types1">
<option value="" selected="selected">类别</option>
<option value="title" >按标题</option>
<option value="content">按内容</option>
<option value="auther">按作者</option>
</select>
<input name="key2" type="text" class="login" id="key2" onclick="this.select()" value="请输入关键字" />
<select name="types" class="login" id="types">
<option value="" selected="selected">类别</option>
<option value="title" >按标题</option>
<option value="content">按内容</option>
<option value="auther">按作者</option>
</select>
<input name="key" type="text" class="login" id="key" onclick="this.select()" value="请输入关键字" />
<input type="submit" name="Submit" value="查找新闻" class="login" />
查询代码:
<%
Dim Key,Types,key2,types1
Key=Request("key")
Types=Request("Types")
key=request("key2")
types1=request("types1")
If (Key="" and key2="")Then
Response.Write "<script language='javascript'>alert('你的关键字不允许为空');location.href='Index.asp'</script>"
response.End()
end if
If (Types="title" and types1="content") then
Sql="select * from NewsInf where title like '%"&Key&"%' and content like '%"&Key2&"%'"
elseif (Types="content" and types1="title") then
Sql="select * from NewsInf where Content like '%"&Key&"%' and title like '%"&Key2&"%'"
elseif (Types="author" and types1="title") then
Sql="select * from NewsInf where author like '%"&Key&"%' and title like '%"&Key2&"%'"
elseif (Types="author" and types1="content") then
Sql="select * from NewsInf where author like '%"&Key&"%' and content like '%"&Key2&"%'"
elseif (Types="content" and types1="author") then
Sql="select * from NewsInf where content like '%"&Key&"%' and author like '%"&Key2&"%'"
elseif (Types="title" and types1="author") then
Sql="select * from NewsInf where title like '%"&Key&"%' and author like '%"&Key2&"%'"
elseif (Types="title" and types1="") then
Sql="select * from NewsInf where title like '%"&Key&"%'"
elseif (Types="" and types1="title") then
Sql="select * from NewsInf where title like '%"&Key2&"%'"
elseif (Types="author" and types1="") then
Sql="select * from NewsInf where author like '%"&Key&"%'"
elseif (Types="" and types1="author") then
Sql="select * from NewsInf where author like '%"&Key2&"%'"
elseif (Types="content" and types1="") then
Sql="select * from NewsInf where content like '%"&Key&"%'"
elseif (Types="" and types1="content") then
Sql="select * from NewsInf where content like '%"&Key2&"%'"
elseif (Types<>"" and types1<>"") then
Response.Write "<script language='javascript'>alert('如果只输入单个条件,请将一边留空');location.href='Index.asp'</script>"
response.End()
end if
Set Rs=Server.CreateObject("ADODB.Recordset")
Rs.Open Sql,conn,1,3
if not rs.eof then
i=1
do while not rs.eof
%>
代码没有语言错误,就是查询不对,请大家帮着改改,谢谢