Solved

Coldfusion Form submit / SQL question

Posted on 2013-06-19
2
496 Views
Last Modified: 2013-06-19
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
Comment
Question by:Bang-O-Matic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39260808
(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
 

Author Closing Comment

by:Bang-O-Matic
ID: 39260830
Works perfect! Thanks _agx_.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question