|
|
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#"
> DBTYPE="ODBC">
> 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)
> </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" />
</cfloop>
</cfquery>
|
|