Solved

help with <cfloop

Posted on 2014-03-11
3
181 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
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

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

10 Experts available now in Live!

Get 1:1 Help Now