cfloop 从 SQL 到总整数值
cfloop to total integer values from SQL
我对 Coldfusion 还很陌生。我正在尝试 运行 一个 cfloop,我在其中经历了从 PostgreSQL table 至今的几个月,并在循环期间将整数值添加到单元格中。单元格已填满一整年,所以我不想要所有单元格,只需要一月到现在。我的代码看起来像这样,但是当我 运行 它时我得到一个 "The value goals.data_1 cannot be converted to a number." 错误。
<cfset ytdGoal = 0>
<cfset mymonth = month(now())>
<cfloop from="1" to="#mymonth#" index="myindex">
<cfset running = ("goals.data_"&myindex)>
<cfset ytdGoal = ytdGoal + #running#>
</cfloop>
如果我进行评估,我就能很好地计算月份数。 PostgreSQL 列设置为整数值。非常感谢任何帮助。
如果我理解您要正确执行的操作,您可以这样使用您的查询。它使您免于使用评估并在列名称为动态时给出值。
<cfset running = goals["data_#myindex#"][currentRow]>
这里是关于使用 ColdFusion 查询作为结构的信息
https://www.raymondcamden.com/2009/11/25/Quick-Tip-Treating-a-ColdFusion-Query-like-a-Structure/
希望对您有所帮助。
我对 Coldfusion 还很陌生。我正在尝试 运行 一个 cfloop,我在其中经历了从 PostgreSQL table 至今的几个月,并在循环期间将整数值添加到单元格中。单元格已填满一整年,所以我不想要所有单元格,只需要一月到现在。我的代码看起来像这样,但是当我 运行 它时我得到一个 "The value goals.data_1 cannot be converted to a number." 错误。
<cfset ytdGoal = 0>
<cfset mymonth = month(now())>
<cfloop from="1" to="#mymonth#" index="myindex">
<cfset running = ("goals.data_"&myindex)>
<cfset ytdGoal = ytdGoal + #running#>
</cfloop>
如果我进行评估,我就能很好地计算月份数。 PostgreSQL 列设置为整数值。非常感谢任何帮助。
如果我理解您要正确执行的操作,您可以这样使用您的查询。它使您免于使用评估并在列名称为动态时给出值。
<cfset running = goals["data_#myindex#"][currentRow]>
这里是关于使用 ColdFusion 查询作为结构的信息 https://www.raymondcamden.com/2009/11/25/Quick-Tip-Treating-a-ColdFusion-Query-like-a-Structure/
希望对您有所帮助。