Steven,

If keywords is actually a comma-separated list of
keywords, using it as you did will only match when
your database contains that same comma-separated list
of keywords in it (an unlikely occurence).

What you have to do is have a "LIKE" condition for
each keyword. If you want a match when ANY of the
keywords match, do as follows:

<cfquery NAME="search" DATASOURCE="search">
 SELECT    ID, title, Description, hyperlink,keywords
 FROM search
 WHERE 1=2
<cfloop list="#keywords#" index="oneKeyword">
  OR keywords LIKE '#oneKeyword#%'
</cfloop>       
</cfquery>
 
If you want a match when ALL the keywords match, do as
follows:
<cfquery NAME="search" DATASOURCE="search">
 SELECT    ID, title, Description, hyperlink,keywords
 FROM search
 WHERE 1=1
<cfloop list="#keywords#" index="oneKeyword">
  AND keywords LIKE '#oneKeyword#%'
</cfloop>       
</cfquery>
 
Sheila Handler
jdt technologies, ltd
--- Steven  Lancaster <[EMAIL PROTECTED]> wrote:
> Without using Verity what is the best way to set up
> a search for keywords
> That I have setup in a database. I have tried
> several different things and
> nothing seems to be working. I am doing a query
> against the database and
> everything works fine except if there is more than
> one keyword it only sees
> the first keyword. my code looks something like
> this: 
> 
> <cfif Len(Trim(keywords))> 
> 
>       <cfquery NAME="search" DATASOURCE="search">
>       SELECT    ID, title, Description, hyperlink,
> keywords
>       FROM search
>       WHERE   keywords LIKE '#keywords#%'
>       </cfquery>
> 
> <cfelse>
> 
>       <h3>You didn't enter a keyword!</h3>
> 
> </cfif>
> 
> 
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to