Forum Moderators: phranque

Message Too Old, No Replies

Coldfusion - Dynamic Array

Use a variable to choose column in array

         

Perseus 2003

2:37 pm on Sep 9, 2003 (gmt 0)



I am having some trouble with coldfusion 4.5 trying to populate an array from a database, however I want to choose what column from the database to use dynamically to pull the information from. It's not working and there must be a way. Here's the code I'm using:

<cfset total_records=test.recordcount>
<cfquery name="Data" datasource="Survey">
SELECT * FROM "DATA"
</cfquery>

<cfset Comments=arraynew(1) />
<cfloop query="Data">
<cfset Comments[CurrentRow]=(#url.RecordID#)>
</cfloop>

When I use a <cfoutput> to view the array, I lines of whatever the url.RecordID variable is set to as opposed to the data from the column to which it refers.

If anyone has any ideas as to how to approach this problem, please let me know.

Double_Dark

8:42 pm on Sep 9, 2003 (gmt 0)

10+ Year Member



<cfset Comments[CurrentRow]=(#url.RecordID#)>

This is just a plain old vanilla assignment statement.

It's the same as

<cfset Comments[CurrentRow] = url.RecordID>

Try

<cfset Comments[CurrentRow] = evaluate("#url.RecordID#")>

Evaluate takes a list of string arguments
evaluate(string1, string2, string3[,...]), evaluates
them, and returns the value of the last string.

Hope this helps.

-DD