theideabulb
asked on
Multi Word Search
I am trying this code example:
<CFQUERY NAME="searchresults" DATASOURCE="yourdatasource ">
SELECT *
FROM table
WHERE 0=0
AND
(
<cfloop index="i" list="#form.searchkeyword# " delimiters=" ">
<cfoutput>fieldname LIKE '%#i#%' AND </cfoutput>
</cfloop>
'%%')
</CFQUERY>
The program I am having is that the last '%%' is giving me no results. If i take that last and '%%' i get the correct results.
Is there a better way to do something like this?
<CFQUERY NAME="searchresults" DATASOURCE="yourdatasource
SELECT *
FROM table
WHERE 0=0
AND
(
<cfloop index="i" list="#form.searchkeyword#
<cfoutput>fieldname LIKE '%#i#%' AND </cfoutput>
</cfloop>
'%%')
</CFQUERY>
The program I am having is that the last '%%' is giving me no results. If i take that last and '%%' i get the correct results.
Is there a better way to do something like this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great solution. Answered my question perfectly
AND would have to find both STAR and WARS
OR would find either STAR or WARS
Typically you would match either, you could give the user the option or choose the one that fits for your app
OR would find either STAR or WARS
Typically you would match either, you could give the user the option or choose the one that fits for your app
ASKER
Say I want to search for DVD and Star Wars, or say the product number for that is 12345 and then of course the title is Star Wars. What is the best way to search for that?