当前位置: 代码迷 >> Sql Server >> 关于搜索的有关问题 sql="select * from wzxx where title like '%"&title&"%' order by id desc"
  详细解决方案

关于搜索的有关问题 sql="select * from wzxx where title like '%"&title&"%' order by id desc"

热度:120   发布时间:2016-04-27 18:03:46.0
关于搜索的问题 sql="select * from wzxx where title like '%"&title&"%' order by id desc"
下面是关于搜索的代码。其中 lbid 是类别。wzxx这个表里是题库表。里面全是题内容和答案。现在问题是。我想让搜索不但搜title的内容。也对content里的内容进行搜索。该如何修改呢。谢谢。

<%if lbid="" and title=""then
sql="select * from wzxx order by id desc"
end if

if lbid="" and title<>""then
sql="select * from wzxx where title like '%"&title&"%' order by id desc"
end if

if lbid<>"" and title=""then
sql="select * from wzxx where lbid="&lbid&" order by id desc"
end if

if lbid<>"" and title<>""then
sql="select * from wzxx where lbid="&lbid&" and title like '%"&title&"%' order by id desc"
end if
dim i,intPage,page,pre,last,filepath
set rs = server.CreateObject("adodb.recordset")
rs.PageSize = 28
rs.CursorLocation = 3
rs.Open sql,conn,0,2,1
pre = true
last = true
page = trim(Request.QueryString("page"))
if page="" then
page=1
end if
if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if
for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for%>
<tr>
<td width="5%" height="22" align="center"><img src="images/point.jpg" width="10" height="12"></td>
<td width="88%" height="22" align="left"><a href="search_view.asp?id=<%=rs("id")%>" target="_blank"><%=rs("title")%></a></td>
<td width="7%" align="left"><font color="#888888">[<%=month(datevalue(rs("tm")))&"/"&day(datevalue(rs("tm")))%>]</font></td>
</tr>
<tr>
<td height="3" colspan="3" align="center" background="images/line.gif"></td>
</tr>
<%rs.movenext
next%>
</table>


<br>
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" align="center">

------解决方案--------------------
SQL code
select * from wzxx where lbid='"&lbid&"' and (title like '%"&title&"%' or [content] like '%"&title&"%') order by id desc
------解决方案--------------------
C# code
上面写错了// 试试这个,不过当数据量比较大的时候性能会有问题sql="select * from wzxx where charindex('" + title + "',title)>0 or charindex('" + title + "',content)>0 ";
------解决方案--------------------
select * from wzxx where lbid="&lbid&" and (title like '%"&title&"%' or [content] like '%"&title&"%') order by id desc
------解决方案--------------------
SQL code
select * from wzxx where  patindex('%'+參數+'%',[title])+ patindex('%'+參數+'%',[content])>0 order by ID desc
  相关解决方案