Solved

Coldfusion Form submit / SQL question

Posted on 2013-06-19
2
494 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
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change database name 2 28
SQL Query including math and 2 tables problem 26 49
Need help on t-sql 2012 10 53
decryping the string data from visa checkout 5 25
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now