Question
SELECT AND/OR
Hi, here is what I am trying to do: I have a large form where
users fill out to search for profiles based on their age, country,
state, personality type, eye color etc etc.
After each form element (country, age, state etc) I have a checkbox with a label "Must Have Criteria". If the user checks this MUST HAVE CRITERIA box for "country=canada" and also for "age=30-45" but selects a personality type of "Out Going" (but did NOT check the MUST HAVE CRITERIA box), then even if there are profiles from Canada who are a personality type "Out Going", if that same profile is not inbetween the age of 30-45, then I want NO RESULTS.
Now, if the user does NOT select the MUST HAVE CRITERIA box for anything, then the results will be based on ANY of the criteria. Does this make sense?
An example of exactly what I want to do can be found at http://personals.yahoo.com/.
After you hit the Search button, you'll notice a left hand multi drop-down menu. Drop down the "Personality Type" and you'll notice at the bottom: "Must Have Criteria". This is what I want to do!
I am assuming that if the MUST HAVE CRITERIA box is checked, then the SQL operater must be an "AND" as opposed to an "OR". Is this how it is done? (Sure aint werkin the way I got it below!)
Here is my SQL statement attempt for a few Form elements:
---------------------------------------------------------------------------------------------------
<!--- STATEPROVINCE --->
<cfelseif isDefined("Form.stateprovince")>
<cfif isDefined("Form.state_musthave")> <<<<<<<<This is the MUST HAVE checkbox
AND stateprovince LIKE '#Form.stateprovince#'
<cfelse>
OR stateprovince LIKE '#Form.stateprovince#'
</cfif>
<!--- CITY --->
<cfelseif isDefined("Form.city")>
<cfif isDefined("Form.city_musthave")> <<<<<<<<This is the MUST HAVE checkbox
AND city LIKE '#Form.city#'
<cfelse>
OR city LIKE '#Form.city#'
</cfif>
<!--- LOOKINGFOR --->
<cfelseif isDefined("Form.lookingfor_checkboxes")>
<cfif isDefined("Form.lookingfor_musthave")> <<<<<<<<This is the MUST HAVE checkbox
AND lookingfor IN
<cfelse>
OR lookingfor IN
</cfif>
(
<cfqueryparam cfsqltype="cf_sql_VARCHAR" list="true"
value="#form.lookingfor_checkboxes#">
)
<!--- PERSONALITY TYPE --->
<cfelseif isDefined("Form.personality_checkboxes")>
<cfif isDefined("Form.personality_musthave")> <<<<<<<<This is the MUST HAVE checkbox
AND personalitytype IN
<cfelse>
OR personalitytype IN
</cfif>
(
<cfqueryparam cfsqltype="cf_sql_VARCHAR" list="true"
value="#form.personality_checkboxes#">
)
---------------------------------------------------------------------------------------------------
Any help in getting this to function would be awsome!
After each form element (country, age, state etc) I have a checkbox with a label "Must Have Criteria". If the user checks this MUST HAVE CRITERIA box for "country=canada" and also for "age=30-45" but selects a personality type of "Out Going" (but did NOT check the MUST HAVE CRITERIA box), then even if there are profiles from Canada who are a personality type "Out Going", if that same profile is not inbetween the age of 30-45, then I want NO RESULTS.
Now, if the user does NOT select the MUST HAVE CRITERIA box for anything, then the results will be based on ANY of the criteria. Does this make sense?
An example of exactly what I want to do can be found at http://personals.yahoo.com/.
After you hit the Search button, you'll notice a left hand multi drop-down menu. Drop down the "Personality Type" and you'll notice at the bottom: "Must Have Criteria". This is what I want to do!
I am assuming that if the MUST HAVE CRITERIA box is checked, then the SQL operater must be an "AND" as opposed to an "OR". Is this how it is done? (Sure aint werkin the way I got it below!)
Here is my SQL statement attempt for a few Form elements:
---------------------------------------------------------------------------------------------------
<!--- STATEPROVINCE --->
<cfelseif isDefined("Form.stateprovince")>
<cfif isDefined("Form.state_musthave")> <<<<<<<<This is the MUST HAVE checkbox
AND stateprovince LIKE '#Form.stateprovince#'
<cfelse>
OR stateprovince LIKE '#Form.stateprovince#'
</cfif>
<!--- CITY --->
<cfelseif isDefined("Form.city")>
<cfif isDefined("Form.city_musthave")> <<<<<<<<This is the MUST HAVE checkbox
AND city LIKE '#Form.city#'
<cfelse>
OR city LIKE '#Form.city#'
</cfif>
<!--- LOOKINGFOR --->
<cfelseif isDefined("Form.lookingfor_checkboxes")>
<cfif isDefined("Form.lookingfor_musthave")> <<<<<<<<This is the MUST HAVE checkbox
AND lookingfor IN
<cfelse>
OR lookingfor IN
</cfif>
(
<cfqueryparam cfsqltype="cf_sql_VARCHAR" list="true"
value="#form.lookingfor_checkboxes#">
)
<!--- PERSONALITY TYPE --->
<cfelseif isDefined("Form.personality_checkboxes")>
<cfif isDefined("Form.personality_musthave")> <<<<<<<<This is the MUST HAVE checkbox
AND personalitytype IN
<cfelse>
OR personalitytype IN
</cfif>
(
<cfqueryparam cfsqltype="cf_sql_VARCHAR" list="true"
value="#form.personality_checkboxes#">
)
---------------------------------------------------------------------------------------------------
Any help in getting this to function would be awsome!