Garbonzo_Horowitz
asked on
How To Create a Coldfusion Struct Using a Query
I would like to create a structure with the data from a query in coldfusion 9.
The data ultimatley needs to be put into a chart for display.
I can not get all of the needed data in my initial query because some of the fields are encrypted and so I have to decrypt them on the page to retrieve the actual values.
I want to create a structure to hold the initial data and the decrypted data and use that as a basis to fill a cfchart.
I'm having a little trouble with the syntax. I've previously have done this type of thing with an array but I'd like to use a structure.
Can you offer some advice on how to correctly create a struct from a cfquery?
This is what I have:
<cfquery name="somequery" >
select field1, encryptedField2 from mytable
</cfquery>
<table>
<tr>
<td>lable1</td>
<td>lable2</td>
</tr>
<cfset MyStruct = StructNew()>
<cfset MyStruct.thing1 = "x">
<cfset Mystruct.thing2 = "y">
<cfoutput query="somequery">
<cfset decryptedVal = #functionToDecrypt#>
<tr>
<td>#field1#</td>
<td>#decryptedField2</td>
</tr>
<cfscript>
StructInsert(MyStruct, "field1", field1)>
StructInsert(Mystruct, "decryptedField2, DecryptedThing)>
</cfscript>
</cfoutput>
</table>
<cfdump var="#MyStruct#">
The data ultimatley needs to be put into a chart for display.
I can not get all of the needed data in my initial query because some of the fields are encrypted and so I have to decrypt them on the page to retrieve the actual values.
I want to create a structure to hold the initial data and the decrypted data and use that as a basis to fill a cfchart.
I'm having a little trouble with the syntax. I've previously have done this type of thing with an array but I'd like to use a structure.
Can you offer some advice on how to correctly create a struct from a cfquery?
This is what I have:
<cfquery name="somequery" >
select field1, encryptedField2 from mytable
</cfquery>
<table>
<tr>
<td>lable1</td>
<td>lable2</td>
</tr>
<cfset MyStruct = StructNew()>
<cfset MyStruct.thing1 = "x">
<cfset Mystruct.thing2 = "y">
<cfoutput query="somequery">
<cfset decryptedVal = #functionToDecrypt#>
<tr>
<td>#field1#</td>
<td>#decryptedField2</td>
</tr>
<cfscript>
StructInsert(MyStruct, "field1", field1)>
StructInsert(Mystruct, "decryptedField2, DecryptedThing)>
</cfscript>
</cfoutput>
</table>
<cfdump var="#MyStruct#">
ASKER
I'm not having an issue decrypting.
All the data needed is being correctly displayed in an html table.
I'm just trying to stuff the results in a struct.
All the data needed is being correctly displayed in an html table.
I'm just trying to stuff the results in a struct.
ASKER
Perhaps a better solution would be to create another query object since the data will ultimately be used in a chart.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok I see what you are saying. Just alter the value on the fly and don't bother with a differnet object. Thanks.
But .. I don't think you need to go through all that trouble. Just loop through the query and decrypt the values in place.
<cfloop query="someQuery">
<cfset someQuery.encryptedField2[
</cfloop>