?
Solved

help with <cfloop

Posted on 2014-03-11
3
Medium Priority
?
188 Views
Last Modified: 2014-03-11
Hi,

I have a multiple select box that has two values.  

I need to insert my values into my table, but not sure how to do it.

My code works fine with one value in my multiple select box, but I have two values this time.

So, I need your help please.

Thanks,
Lulu

The number in the select is the segment 
the name in the select is the group name

<select name="DispSelectedGroupBox" class="SearchBySelect5" id="DispSelectedGroupBox" style="background-color: #f8fafc; width: 250px; height: 100px;" size="180" multiple="multiple" sizzle-1394543330211="[object Object]">

<option value="2,A & A DRIVING SCHOOL" data-companyname="A & A DRIVING SCHOOL"></option>

<option value="2,A & A HARDWARE & AUTO SUPPLY" data-Companyname="A & A HARDWARE & AUTO SUPPLY"></option>

<option value="2,A & A MANUFACTURING INC" data-Companyname="A & A MANUFACTURING INC"></option>

</select>


<cfloop list="#FORM.DispSelectedGroupBox#" index="GroupImpacted" delimiters=","> 

<cfquery name = "QGroupImpacted"  datasource='#strDSN#' username='#strUID#' password='#strPWD#'>

INSERT INTO SelectedGroup (GroupName, SegmentID, IssueID, CreatedDate)
VALUES (

	<cfif #form.DispSelectedGroupBox# neq ''>
<cfqueryparam cfsqltype="cf_sql_integer" value="#GroupImpacted.GroupName#">, 
			</cfif>
<cfif #form.DispSelectedGroupBox# neq ''>
<cfqueryparam cfsqltype="cf_sql_integer" value="#GroupImpacted.SegmentID#">, 
			</cfif>
     #IssueIDVal#,      
  <cfqueryparam cfsqltype="cf_sql_date" value="#Now()#" />
)
</cfquery> 
</cfloop>

Open in new window

0
Comment
Question by:lulu50
[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
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 2000 total points
ID: 39920448
First you have to change the delimited in the option value to a semicolon instead of a comma.   Having a comma between the 2 and the Name causes confusion between the list of options selected (delimited by a comma) and the separation of the ID and the Name.


<!---- you have to change the delimiter between the 2 and the Name to a ; so it doesn't get confused with the comma delimited list of selected options ---->
<select name="DispSelectedGroupBox" class="SearchBySelect5" id="DispSelectedGroupBox" style="background-color: #f8fafc; width: 250px; height: 100px;" size="180" multiple="multiple" sizzle-1394543330211="[object Object]">
  <option value="2;A & A DRIVING SCHOOL" data-companyname="A & A DRIVING SCHOOL"></option>
  <option value="2;A & A HARDWARE & AUTO SUPPLY" data-Companyname="A & A HARDWARE & AUTO SUPPLY"></option>
  <option value="2;A & A MANUFACTURING INC" data-Companyname="A & A MANUFACTURING INC"></option>
</select>


<!---- this will loop for each of the selections of the drop down box, one loop for each selected option ---->
<cfloop list="#FORM.DispSelectedGroupBox#" index="GroupImpacted" delimiters=","> 
    <!---- this will split the value of the selected option into the two parts, the ID and the Name ---->
    <cfset theID   = listFirst(GroupImpacted,";")>
    <cfset theName = listLast(GroupImpacted,";")>

	<cfquery name = "QGroupImpacted"  datasource='#strDSN#' username='#strUID#' password='#strPWD#'>
	   INSERT INTO SelectedGroup (GroupName, SegmentID, IssueID, CreatedDate)
	   VALUES (
	         <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#theName#">
			,<cfqueryparam cfsqltype="cf_sql_integer" value="#theID#">
	        , #IssueIDVal#
	        , <cfqueryparam cfsqltype="cf_sql_date" value="#Now()#" />
	    )
	</cfquery> 
</cfloop> 

Open in new window

0
 

Author Comment

by:lulu50
ID: 39920545
gdemaria,

Thank you for your help!!!

It works!!! Great!!!!

Thank you again lol

Lulu
0
 

Author Closing Comment

by:lulu50
ID: 39920549
Excellent ++
0

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

719 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