Re: Search Based on Multiple Checkboxes
On 26 Jul, 08:53, "jerreye04" <webforumsu...@xxxxxxxxxxxxxx> 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#"
> SELECT *
> FROM table
> WHERE ID = #Session.ID#
> AND country LIKE '#Form.country#'
> AND stateprovince LIKE '#Form.stateprovince#'
> AND interests LIKE ????? (one or more checkboxes checked)
> 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!
> [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
select * from ...
<cfloop index="item" list="#form.interests#" delimiters=",">
and interests (search_table_field) like <cfqueryparam value="#item#%"