>SELECT * from prds
>WHERE 1=1
> AND (prds.title like '%test%'
> OR prds.title like '%test1%')
>
>How to implement that logic for more than 3 keywords(on the fly)?
>
>Thanks
>Raj

I would create a loop through the key words.  I guess that you would have to 
count them band base that on a delimeter of some type if you were having the 
user enter them so that you had an ending value and wouldn't run into a 
variable not defined error.

something like:
<cfset i = 0>

SELECT * from prds
WHERE 1=1
and (
<cfloop from="1" to="numberofkeywords" index="i">
<cfif i eq 1>
prds.title like '%test#i#%' or
</cfif>
prds.title like '%test#i#%' or
<cfif i eq numberofkeywords>
prds.title like '%test#i#%'
</cfif>
)

This assumes that you have at least two keywords.  error checking would have to 
be added if there is only going to be one or no keywords, as that will affect 
the query statement.

Hope that helps.

Rob



 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get the answers you are looking for on the ColdFusion Labs
Forum direct from active programmers and developers.
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72&catid=648

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:285084
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to