ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 14th, 2004, 09:21 AM
buttons buttons is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 9 buttons User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 17 sec
Reputation Power: 0
multiple selections from listbox into a query

Hi all,

Am getting stuck on how to code the query using multiple selections from a listbox (named which_fields). Have read various threads and can't get what others say to work.

The scenario for this prob is: I want the user to be able to select from a listbox (which contains a list of all the fields in the GENERAL_NEEDS_CLEAN_test table in the database) which fields they want to process in the query. Multiple fields selections are needed. So I have created a listbox (which allows multiple selections) using the following code (note: only the first part of the cfform code shown here but the CFForm tag works fine):

<CFFORM name="DateForm" ACTION="Download.cfm" METHOD="post">

<tr><td><B>Step 1. Select fields to download:</B>
<cfselect name="which_fields" display= "label" required="yes" multiple="YES" size="5">
<option value="All FIELDS" selected="selected">All Fields</option>
<cfoutput><cfloop list="#database_fields.ColumnList#" index="MyColumnName">
<option value="#MyColumnName#">#MyColumnName#</option></cfloop></cfoutput></cfselect></td><td></td></tr>


Then I send the form variables through to the action page using CFForm and use the following query....but when I run the query I get no results.


<cfquery name="export_selected_all_records" datasource="supporting_peopleTESTDB">
SELECT *
FROM GENERAL_NEEDS_CLEAN_test
WHERE ManagingAssoc = '#CLIENT.id#' AND 'form.which_fields' = '#form.which_fields#'
</cfquery>


What am I getting wrong?? It is possible to do what I'm asking in ColdFusion. All the other posts I've read have done slightly different things.

Can anyone advise me??

Reply With Quote
  #2  
Old June 14th, 2004, 10:05 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
Of course this is possible. The problem is in your SELECT statement. You probably want to use the IN operator, but I can't tell from your query what database field you want to limit the results by. You probably want something like this:

<cfquery name="export_selected_all_records" datasource="supporting_peopleTESTDB">
SELECT *
FROM GENERAL_NEEDS_CLEAN_test
WHERE ManagingAssoc = '#CLIENT.id#' AND someDatabaseColumn IN (#quotedValueList( form.myMultipleSelectField )#)
</cfquery>
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old June 15th, 2004, 03:57 AM
buttons buttons is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 9 buttons User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 17 sec
Reputation Power: 0
Thanks for your reply.

I'm not sure what you mean by this..."but I can't tell from your query what database field you want to limit the results by"....

I don't know what database fields the user wants from the database. They have to choose it from the list box. The list box allows them to select the 'all fields' option to get all fields from the database or multiple selected fields of their choice. So I don't know what the 'someDatabaseColumn' is (and there may be many requested) until the user is on-line completing the form. I have so many fields in the database that to write each field out in the query seems repetative and therefore there must be a better solution surely??

WHERE ManagingAssoc = '#CLIENT.id#' AND someDatabaseColumn IN (#quotedValueList( form.myMultipleSelectField )#)


Thanks for any help.

Reply With Quote
  #4  
Old June 15th, 2004, 09:16 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
So if the user is picking which fields they want to search for, how do you know what value in each field to limit the query by?

Or are you trying to say that you want the result set to only return the columns that the user picked, like this:

<cfquery name="export_selected_all_records" datasource="supporting_peopleTESTDB">
SELECT #form.which_fields#
FROM GENERAL_NEEDS_CLEAN_test
WHERE ManagingAssoc = '#CLIENT.id#'
</cfquery>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > multiple selections from listbox into a query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway