Solved

help with <cfloop

Posted on 2014-03-11
3
186 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 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

615 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