On 4/5/00, Stuart Duncan penned:
> <cfif findnocase(' ',keyword)>
> <!--- Search for Everything on Each side of space --->
> <cfloop list="#keyword#" index="keywords" delimiters=' '>
> <cfquery datasource="#db#" name="search_results">
> select *
> from table
> where name LIKE '%#keywords#%'
> </cfquery>
> <cfoutput query="search_results">#item1# - #item2#<br></cfoutput>
> </cfloop>
>
>
>
>I get back High School, High School, High Jump. Even though there's only
>one High School and one High Jump in the db.
>It finds it once for High and then again for School.
Your running the full query inside the loop, so it's returning all
the records for High (two of them), then all the records for school
(one of them).
Put the loop inside the query.
No need to specify the cfif. It will automatically loop if there are
space delimiters, or loop once if they enter one word.
The 0=1 will just let the loop end smoothly.
<cfquery datasource="#db#" name="search_results">
select *
from table
where <cfloop list="#keyword#" index="keywords" delimiters=' '>
name LIKE '%#keywords#%' or</cfloop> 0=1
</cfquery>
<cfoutput query="search_results">#item1# - #item2#<br></cfoutput>
Bud Schneehagen - Tropical Web Creations
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ColdFusion Solutions / eCommerce Development
[EMAIL PROTECTED]
http://www.twcreations.com/
954.721.3452
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.