• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

strange ouput

Explorer ,
Nov 08, 2006 Nov 08, 2006

Copy link to clipboard

Copied

the values of variables.otherfundingsource is 9,21,97.

<cfset variables.otherfundingsource = "9,21,97">
And before inserting they are same which are 9,21,97.

debugging: before insert - variables.otherfundingsource: <cfoutput>#variables.otherfundingsource#</cfoutput>

<cfquery name="r03201_child_insert" datasource ="testdb">
<cfloop list="#variables.otherfundingsource#" index="variables.otherfundingsource">
insert into #variables.sub01table#
([#variables.foreignid#],
[otherfundingsource])

values (#variables.index_id#,
#variables.otherfundingsource#)
</cfloop>
</cfquery>
</cfif>

debugging: after insert - variables.otherfundingsource: <cfoutput>#variables.otherfundingsource#</cfoutput>
after inserting, the output of variables.otherfundings shows only "97"

why the one value which is "97" is showing up other than three of them which are 9,21,97. what went wrong? shouldn't it output 9,21,97?
TOPICS
Advanced techniques

Views

233

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 08, 2006 Nov 08, 2006

Copy link to clipboard

Copied

Because of this line

<cfloop list="#variables.otherfundingsource#"
index="variables.otherfundingsource">

The index parameter is the variable to store each value of the list as
it is looped over. So as you loop over the list, [9,21,97], you are
assigning each of these values to "variables.otherfundingsource". Thus
at the end of the loop, variables.otherfundingsource is going to equal
the last value in the list, i.e. 97.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 09, 2006 Nov 09, 2006

Copy link to clipboard

Copied

thanks. i need that loop to insert values and need those three values again for something else.
what can be a way to get three values? should i make a query to retrieve them? is there any other way to get those values without runnig query again?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 09, 2006 Nov 09, 2006

Copy link to clipboard

Copied

LATEST
Just provide an independent variable for your loop iterations so you are
not overwriting the original variable.


<cfloop list="#variables.otherfundingsource#" index="sourceID">
<cfoutput>#sourceID#</cfoutput>
</cfloop>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation