Skip to main content
Inspiring
November 8, 2006
Question

strange ouput

  • November 8, 2006
  • 1 reply
  • 288 views
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?
This topic has been closed for replies.

1 reply

Inspiring
November 8, 2006
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.
Inspiring
November 9, 2006
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?