|
This is probably really simple, but i`m having a no dice kinda week...
<%
Dim rsResults__MMColParam
rsResults__MMColParam = "1"
If (Request.Form("data") <> "") Then
rsResults__MMColParam = Request.Form("data")
End If
%>
What I want it to do is seperate the words coming from DATA into single words and apply each word to the recordset query, so that when it gets to..
SELECT * FROM faq WHERE question LIKE `%" + Replace(rsResults__MMColParam, "`", "``") + "%` ORDER BY ranking DESC"
it tests each (single) word from the request.form("data") against the question collumn in my database.
Thanks in advance for any help.
James
|
|
|
1. Break the string into an array of single words. The VBScript Split() function defaults to splitting strings on single spaces.
aryX = Split(rsResults__MMColParam)
2. Next, build the sql statement. The Split() function will create an array even if there is only one item in the array. (index 0). Since you are first making sure the variable contains a value, we can be sure that we will end up with an array. Otherwise, you`d first want to test to make sure you have an array to work with (IsArray() function).
sql = "select *" & _
" from faq" & _
" where (question like `%" & aryX(0) & "%`"
aryLen = UBound(aryX)
if aryLen > 0 then
for i = 1 to UBound(aryX)
sql = sql & _
" or question like `%" & aryX(i) & "%`"
next
end if
sql = sql & ")"
End If
%>
The sql statement produced by this code will find all faqs where the question contains a match to at least one of the conditions. If you wanted it to match ALL the words, then change the ORs to ANDs. Don`t be surprised if you copy & paste this and get an error or two. I average 1 error for every 2 lines of code I write!
|
|
|
|
|
|
|
|
|
|
|
|