faqts : Computers : Programming : Languages : Asp : ASP/VBScript : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 20 people (80%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I make multiple keyword searches?

May 16th, 2000 23:01
unknown unknown, Brandon Holmes


I passed the search string as a query string, broke it up into the
individual words and assembled a SQL query from the keywords using an 
array.

<!-- splits search string and creates an sql query -->

<%
dim dbconn
dim rs
dim sql
dim asql

   asql = ""
   arrSearch = Split(trim(request.querystring("searchstring")), " ")
   sql ="select * from *  where * "

   For i = 0 to (UBound(arrSearch))
      asql = asql + "and * Like '%" & arrSearch(i) & "%'"
   Next

   sql = sql & asql & "order by p.description asc"
   Set dbconn = Server.CreateObject ("ADODB.connection")
   dbconn.open " * ;"
   set rs= dbconn.Execute(sql)
%>

Fill the * with your DB info and viola.  Took me a few hours but works 
like a charm.  This will return a recordset containing only entries
that have ALL the keywords.  So if the search string is Bill Clinton, it
returns 'Bill and Clinton' instead of 'Bill or Clinton'. grr, now just 
have to work this into a stored procedure...



© 1999-2004 Synop Pty Ltd