Solved

help with <cfloop

Posted on 2014-03-11
3
177 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
Comment Utility
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
Comment Utility
gdemaria,

Thank you for your help!!!

It works!!! Great!!!!

Thank you again lol

Lulu
0
 

Author Closing Comment

by:lulu50
Comment Utility
Excellent ++
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 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

9 Experts available now in Live!

Get 1:1 Help Now