[Top] [All Lists]

Re: Search Based on Multiple Checkboxes

Subject: Re: Search Based on Multiple Checkboxes
Date: Thu, 26 Jul 2007 04:11:00 -0700
Newsgroups: macromedia.coldfusion.cfml_general_discussion
On 26 Jul, 08:53, "jerreye04" <[email protected]> wrote:
> Hi, I have a form where the user can select multiple checkboxes (i.e.
> "interests checkboxes" = skiing, hiking, cliff jumping etc etc )
>  Here is my code:
>  <CFQUERY NAME="GetAdvancedSearchResults" datasource="#Application.dSource#"
>  FROM table
>  WHERE ID = #Session.ID#
>  AND country LIKE ''
>  AND stateprovince LIKE '#Form.stateprovince#'
>  AND interests LIKE ????? (one or more checkboxes checked)
>  </cfquery>
>  How would I check the values of multiple checkbox selections and select
> eveything from my database based on all checked checkboxes? I assume I must
> create a ListAppend Array or something within the SQL statement?
>  Any help would be great!
>  Jeremy
>  [b]Here is my attempt at the code:[/b][b]AND interests LIKE ?????[/b][u]AND
> interests LIKE ????? (one or more checkboxes checked)[/u]

If you use:
<checkbox name="interests" id="interests_skiing" value="skiing" />
<checkbox name="interests" id="interests_hiking" value="hiking" />
then on submit you will receive one CGI/CF form variable interests
with comma separated values of all checked checkboxes.
then in your query
<cfquery ...>
select * from ...
where 1=1
<cfloop index="item" list="#form.interests#" delimiters=",">
        and interests (search_table_field) like <cfqueryparam value="#item#%"
cfsqltype="cf_sql_varchar" />

<Prev in Thread] Current Thread [Next in Thread>