使用 cfloop 索引形成值
Form values using cfloop index
我正在使用 cfloop 创建表单并使用数据库查询中的值填充文本字段。我还创建了一个数组。它在输入框中返回 "depthinput1"、"deptinput2" 等,而不是数据库字段中的值。任何帮助将不胜感激。
<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>
我想你想要的更像是:
<cfoutput query="flowQy">
<input name="depthinput#currentRow#" type="text" ... value="#somecolumninQuery#" id="depthinput#currentRow#" />
</cfoutput>
很难说出您的代码试图做什么,或者您试图引用的数据到底在哪里。
没有数据转储,很难说出数据实际是如何存储的,这让问题有点混乱。
"depthinput1"、"depthinput2"是查询中的列名吗?
RecordID | DepthInput1 | DepthInput2 | ... | DepthInputN
1 | 35.5 | 86.2 | ... | 14.6
... 或者 "depthInput" 值实际上存储在单独的行中吗?
RecordID | DepthInput
1 | 35.5
2 | 86.2
....
86 | 14.6
如果它们是查询列,请考虑重组数据库 table。类似的列名,如 "thing1"、"thing2"、...通常表明数据应存储在单独的行中(如上所示)。如果你真的不能改变结构,使用关联数组表示法动态访问查询列,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>
如果值实际上存储在单独的行中,只需循环查询并使用 queryName.currentRow
作为索引。
<cfoutput query="flowQy">
<input name="depthInput#flowQy.currentRow-1#"
value="#flowQy.depthInput#"><br>
</cfoutput>
我正在使用 cfloop 创建表单并使用数据库查询中的值填充文本字段。我还创建了一个数组。它在输入框中返回 "depthinput1"、"deptinput2" 等,而不是数据库字段中的值。任何帮助将不胜感激。
<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>
我想你想要的更像是:
<cfoutput query="flowQy">
<input name="depthinput#currentRow#" type="text" ... value="#somecolumninQuery#" id="depthinput#currentRow#" />
</cfoutput>
很难说出您的代码试图做什么,或者您试图引用的数据到底在哪里。
没有数据转储,很难说出数据实际是如何存储的,这让问题有点混乱。
"depthinput1"、"depthinput2"是查询中的列名吗?
RecordID | DepthInput1 | DepthInput2 | ... | DepthInputN
1 | 35.5 | 86.2 | ... | 14.6
... 或者 "depthInput" 值实际上存储在单独的行中吗?
RecordID | DepthInput
1 | 35.5
2 | 86.2
....
86 | 14.6
如果它们是查询列,请考虑重组数据库 table。类似的列名,如 "thing1"、"thing2"、...通常表明数据应存储在单独的行中(如上所示)。如果你真的不能改变结构,使用关联数组表示法动态访问查询列,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>
如果值实际上存储在单独的行中,只需循环查询并使用 queryName.currentRow
作为索引。
<cfoutput query="flowQy">
<input name="depthInput#flowQy.currentRow-1#"
value="#flowQy.depthInput#"><br>
</cfoutput>