
May 8th, 2008, 11:32 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Time spent in forums: 2 h 31 m 41 sec
Reputation Power: 0
|
|
|
Multiple keyword search for one field
I have one search field that the user can put in several words (separated by space). I would like to break this string up and query the table on all the words from this string. For example, if the user enters "Doe Smith Johnson Williams", I want to search the table and pull up all records with Last Name = Doe AND Smith AND Johnson AND Williams.
I've searched and found several examples, but they are all in php. I've tried to convert to asp but it doesn't seem to be working.
Also this php code I used was based off of searching more than one column (field?) So I was also trying to eliminate the multiple column part of the code, and just have it search off of one field.
PHP Code:
dim keywords(20)
dim Lnamestring
dim search_columns(1)
search_columns(0)="LName" 'this was where you would put multiple search columns...i just stuck my one in there
Lnamestring = CCGetFromGet("s_LName", Empty)
Lnamestring = trim(Lnamestring)
keywords = split(Lnamestring)
Employee2.datasource.Where = " "
dim p
p = 0
Employee2.DataSource.Where = Employee2.DataSource.Where & "("
dim word
dim m
dim column
for each word in keywords
if (len(word) > 2) then
if (p <> 0) then
Employee2.DataSource.Where = Employee2.DataSource.Where & ") AND ("
p=1
m=0
end if
for each column in search_columns
if (m <> 0) then
Employee2.DataSource.Where = Employee2.DataSource.Where & " OR "
Employee2.DataSource.Where = Employee2.DataSource.Where & " column LIKE '%word%' "
m=1
end if
next 'end foreach column
end if
next ' foreach word
Employee2.DataSource.Where = Employee2.DataSource.Where & ")"
|