Chris,

I agree with some of the other comments that your database design might need
some work, but as an answer to your question I'll propose this.  Say your
form has a field called FORM.strKeywords which is the field in which the
user will type a set of keywords separated by spaces.  Here's what you'll
want to do on the page that the search form submits to:

<!--- find all records with matching keywords --->
<cfquery name="qSearch" datasource="yourDSN">
        SELECT
                id
        ,       strName
        ,       strKeywords
        FROM
                tblYourTableName
        WHERE
                1=1
        <cfloop list="#trim(form.strKeywords)#" index="keyword" delimiters=" ">
                AND     strKeywords LIKE '%#keyword#%'
        </cfloop>
</cfquery>

Of course, this will only find records which match ALL of the keywords a
user entered.  I think you should be able to figure out how to adapt this to
finding ANY matching records if that's what you wanted.

Hope this helps,
Tyson

------------------------------------------------
Tyson Vanek, Technical Lead
duoDesign, The eBusiness Architects
Building your business online

847.491.3000 main | [EMAIL PROTECTED]
847.491.3100 fax | www.duodesign.com
847.491.4270 direct | www.chicagoangels.org

Come to our free 2-hour seminar "The eBusiness Squeeze"
http://www.duodesign.com/squeeze/seminar.html

-----Original Message-----
From: Chris Geanious [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 21, 2001 11:01 PM
To: CF-Talk
Subject: Looping through lists


Greetings,
Am constructing a db search using (among other things) a form text area for
keywords.  In the data base there is a KeyWords field which contains a
comma delimited list of keywords for each entry.

I have a query which loops over the form text box entries.  How do I then
loop over the database keyword fields to check for a match?  I am a little
stuck.  Any suggestions, code snippets, links to sites would be greatly
appreciated.

TIA,

Chris
==============================
Chris Geanious
Support Systems Analyst Senior
Institute For Human Development
Northern Arizona University
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
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