Solved

Coldfusion Form submit / SQL question

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

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…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

18 Experts available now in Live!

Get 1:1 Help Now