[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

Coldfusion Form submit / SQL question

I have added "multiple" to my select dropdown, but I'm not sure how to adjust my SQL query on the action page to compensate for multiple city selections? Any help appreciated!

screenshot of multiselect menu
<cfselect name = "City" query = "city" value = "City" queryPosition="below" selected = "#prefillCity#" class="selectpicker show-menu-arrow span6" multiple>
      <option value=" ">All Cities</option>
      </cfselect>


<!---QUERY ON FORM ACTION PAGE--->
<cfquery name="listings" datasource="datasource" result="result">
SELECT * from res INNER JOIN seo on res.Listid = seo.Listid
WHERE 0=0

<!---Search by City--->
<cfif StructKeyExists(form,"City") and len(trim(form.City))>
 AND City = '#form.City#'
</cfif>
0
Bang-O-Matic
Asked:
Bang-O-Matic
1 Solution
 
_agx_Commented:
(Edit) Since the field will now contain multiple cities, the SQL should switch to an IN (....) clause instead of equals (single comparison only).  ie WHERE City IN ( 'list', 'of', 'city', 'names')

<!---Search by City--->
<cfif StructKeyExists(form,"City") and len(trim(form.City))>
 AND City IN (
         <cfqueryparam value="#form.City#" cfsqltype="cf_sql_varchar" list="true">
     )
</cfif>
0
 
Bang-O-MaticAuthor Commented:
Works perfect! Thanks _agx_.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now