Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

help with <cfloop

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
lulu50
Asked:
lulu50
  • 2
1 Solution
 
gdemariaCommented:
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
 
lulu50Author Commented:
gdemaria,

Thank you for your help!!!

It works!!! Great!!!!

Thank you again lol

Lulu
0
 
lulu50Author Commented:
Excellent ++
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now