Something like this

<cfif IsDefined("form.criteria") AND Len(Trim(form.criteria))>
and (
        <cfset c=0>
        <cfloop index=wrd list="#form.criteria#" delimiters=" ">
                <cfset c=c+1>
                itemName LIKE '%#wrd#%'
                <cfif c neq listlen(form.criteria," ")> OR </cfif>
        </cfloop>
)
</cfif>

-----Original Message-----
From: Colin Eyo [mailto:[EMAIL PROTECTED] 
Sent: Saturday, April 12, 2008 12:36 PM
To: CF-Talk
Subject: A Better Coldfusion Search Form.

Hi,

I'm trying to figure out how to create a dynamic search form using
Coldfusion 8. 

Right now if I enter multiple words in my search field the results omit
certain records. For example, if I put "toy blue" in the search field it
will return results that only have "TOY BLUE" together and omits any records
that only have "TOY" or only have "Blue" in the column being searched.

Is there a way to add the following abilities to my basic search code
located at the bottom of my post:

- Search multiple words that are entered in the criteria input field.
- The words can be separated by commas, spaces, or the word "and".
- Have it so you can search multiple word phrases by using quotes.

<!--- Search Form--->
 
  <form name="myForm" method="post" action="results.cfm">
  <p>
    <input name="criteria" type="text" id="criteria">
    <input type="submit" name="Submit" value="Submit">
  </p>
  </form>

<!--- Results Page --->

<cfquery name="qSearch" datasource="myDatabase" dbtype="ODBC">
        SELECT itemID, itemName
        FROM myTable
        WHERE 1 = 1
        
        <cfif IsDefined("form.criteria") AND Len(Trim(form.criteria))>
                and (itemName LIKE '%#form.criteria#%' or itemDescription
LIKE '%#form.criteria#%')
        </cfif>

</cfquery>

<p><b>Results:</b></p>
<cfoutput query="qSearch">
        <p>#itemid# - #itemName#</p>
</cfoutput>

<!--------->

Any help would be greatly appreciated.

Thanks

-C 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:303232
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