...

View Full Version : Q about search...



ugmos
02-23-2006, 08:03 PM
Hi all...
I did a search form...
when user write in the form: Moscow
The form give him all the results with the word Moscow

But when he write Moscow London the result is 0 entries...

BUT in the table we can find Moscow to London

And the search ignores this. cuz he search's full frase...

What should i do th show the user Moscow to London if he search Moscow london...

Here's the code:

Code:

strSQL = "SELECT marsh, polnyi, id " _
& "FROM Question " _
& "WHERE marsh LIKE '%" & Replace(strpoisk, "'", "''") & "%' " _
& "OR polnyi LIKE '%" & Replace(strpoisk, "'", "''") & "%' " _
& "ORDER BY id;"

Sorry for my English... and thank for your help!

glenngv
02-24-2006, 11:22 AM
Split the keyword by space to have an array of keywords and then form the LIKE condition for each keyword

ugmos
02-24-2006, 03:06 PM
Thanks for your Re...

can you show me please how to do this...
I already figured it out that i need to split the words by space....

But i don't know how to... :(

degsy
02-24-2006, 03:26 PM
Maybe something like this



<%
If Len(Request.Form) > 0 Then
term = Trim(Request.Form("search"))
term = Replace(term,"'","''")

If InStr(term," ") > 0 Then
term = Split(term," ")

For x=0 to Ubound(term)
If x > 0 Then
clause = clause & " AND"
End If
clause = clause & " location LIKE '%" & term(x) & "%'"
Next
Else
clause = " location LIKE '%" & term & "%'"
End If

sql = " WHERE " & clause
'sql = "SELECT * FROM location WHERE" & clause
'Response.Write sql
End If
%>


It's only a quick basic version though.

Bullschmidt
03-07-2006, 02:28 AM
And:

Classic ASP Design Tips - Search For Keywords on Multiple Fields
http://www.bullschmidt.com/devtip-searchmultiplefields.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum