複数行のレコードを含むクエリがあります。構造体の各行を列名キーで出力したいと思います。クエリレコードをループした後、その構造を配列に設定したいと思います。これまでのところ、データの正しい形式がありますが、何らかの理由でデータの各行が同じです。すべてのデータが 1 つの行から取得されているようです。これが私のコードの例です:
<cfset strGraphData = StructNew()>
<cfset arrGraphData = arrayNew(1)>
<cfquery name="getGraphData" datasource="myDB">
SELECT gr_date, gr_LabelA, gr_LabelB
FROM GraphData WITH (NOLOCK)
WHERE gr_ID = <cfqueryparam value="#arguments.graphID#" cfsqltype="cf_sql_integer">
ORDER BY gr_date ASC
</cfquery>
<cfoutput query="getGraphData">
<cfloop list="#getGraphData.getColumnNames()#" index="columnName">
<cfset strGraphData[columnName] = Trim(getGraphData[columnName][getGraphData.CurrentRow])>
</cfloop>
<cfset arrayAppend(arrGraphData, strGraphData)>
</cfoutput>
配列をダンプしようとすると、出力は次のようになります。
array
1
struct
GR_DATE 2014-05-12 00:00:00.0
GR_LABELA 17
GR_LABELB [empty string]
2
struct
GR_DATE 2014-05-12 00:00:00.0
GR_LABELA 17
GR_LABELB [empty string]
3
struct
GR_DATE 2014-05-12 00:00:00.0
GR_LABELA 17
GR_LABELB [empty string]
4
struct
GR_DATE 2014-05-12 00:00:00.0
GR_LABELA 17
GR_LABELB [empty string]
5
struct
GR_DATE 2014-05-12 00:00:00.0
GR_LABELA 17
GR_LABELB [empty string]
6
struct
GR_DATE 2014-05-12 00:00:00.0
GR_LABELA 17
GR_LABELB [empty string]
7
struct
GR_DATE 2014-05-12 00:00:00.0
GR_LABELA 17
GR_LABELB [empty string]
8
struct
GR_DATE 2014-05-12 00:00:00.0
GR_LABELA 17
GR_LABELB [empty string]
9
struct
GR_DATE 2014-05-12 00:00:00.0
GR_LABELA 17
GR_LABELB [empty string]
実際のデータ クエリの例を次に示します。
GR_DATE
2014-01-14 00:00:00.000
2014-02-04 00:00:00.000
2014-02-18 00:00:00.000
2014-03-04 00:00:00.000
2014-03-18 00:00:00.000
2014-04-01 00:00:00.000
2014-04-15 00:00:00.000
2014-04-29 00:00:00.000
2014-05-12 00:00:00.000
GR_LABELA
1
3
5
5
10
16
16
16
17
GR_LABELB
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
ご覧のとおり、構造体の配列のデータは最後の行のデータを繰り返します。私のコードのどこにバグがあるのか わかりません。誰かがこの問題を解決する方法を知っているなら、私に知らせてください。ありがとう。