I'm using a cfloop to create a form and populate text fields with values from a database query. I also created an array. It is returning "depthinput1", "deptinput2", and so on in the input boxes, instead of the values in the database fields. Any help would be appreciated.
<cfloop index="i" from="0" to="#totalsegment-1#">
<cfloop query="flowQy" startrow="1" endrow="#totalsegment-1#">
<cfset newarray =ArrayNew(1)>
<cfset depthinput=structNew()>
<cfset depthinput[i] = "depthinput" & i>
<cfset arrayAppend(newarray, depthinput)>
<cfinput name="depthinput#i#" tabindex="#((i+1)*2)-1#" type="text" onfocus="this.value='';findTotal();" size="10" onblur="findTotal();" value='#depthinput[i]#' id="depthinput#i#"></cfinput></br>
</cfloop>
</cfloop>
Without a data dump, it's difficult to tell how the data is actually stored, which makes the question a little confusing.
Are "depthinput1", "depthinput2" the names of columns in the query?
RecordID | DepthInput1 | DepthInput2 | ... | DepthInputN
1 | 35.5 | 86.2 | ... | 14.6
... OR are the "depthInput" values actually stored in separate rows ?
RecordID | DepthInput
1 | 35.5
2 | 86.2
....
86 | 14.6
If they're query columns, consider restructuring the database table. Similar column names like "thing1", "thing2", ... are usually an indicator the data should be stored in separate rows (like above). If you really can't change the structure, use associative array notation to access the query columns dynamically, queryName["columnName"][rowNumber]#
:
<cfoutput query="flowQy">
<!--- determines which columns to display: -->
<cfloop from="0" to="#totalSegment#" index="i">
<input name="depthInput#i#" value="#flowQy['depthInput'& i+1][flowQy.currentRow]#"><br>
</cfloop>
</cfoutput>
If the values are actually stored in separate rows, just loop through the query and use queryName.currentRow
as an index.
<cfoutput query="flowQy">
<input name="depthInput#flowQy.currentRow-1#"
value="#flowQy.depthInput#"><br>
</cfoutput>