This content has been marked as final. Show 6 replies
perhaps the columnlist variable of cfquery might be of use.
Details are in the cfml reference manual or livedocs. Search on <cfquery>
Thanks both to Dan Bracuk and Bob Dobbs, but the problem I was having was to get the VALUE of the variable represented by the column names, not the column names themselves. I already have that, but WHICH column are in the query depends on the selections made. The usual situation is for a person to select items IN A SPECIFIC COLUMN (like "color" or "name" column). Everything I found required me to specify the field name, which itself is a variable. Got the help I needed on the DaniWeb Forum. FYI, it was the "evaluate" function that did the trick. Thanks anyway!
> but the problem I was having was to get the VALUE of the variable represented by the column
> names, not the column names themselves ...
> FYI, it was the "evaluate" function that did the trick.
The evaluate function is not needed. To retrieve a column value just use associative array notation.
You can view an example in the QueryToCSV2 function at cflib.org. It uses the columnList variable (mentioned earlier) with array notation to retrieve the actual column values:
I tried that, but as far as I could figure you still have to have a specific column name, not a variable which contains the colum name in the ["yourColumnName"] part. I have a cfselect with multiple set to "yes" and the selections are "which columns of data do you want to see?" The resulting variable is a comma delimited string. I then need to use that string variable to display the results (the VALUES) ONLY OF THE COLUMNS SELECTED. The evaluate function is the only thing that seems to do this.
> I tried that, but as far as I could figure you still have to have a specific column name
Look at the udf more closely. If you read the documentation it states all of the parameters are optional, except the query. So if you do not supply column names, the function will use the columnList variable to determine the names of the columns in the query. If you look at the actual code, notice it uses array notation to extract the values (not evaluate) .
... (code to create query) ...
<!--- pass in the query object only ---->
<cfset test = QueryToCSV2( data )>
> I have a cfselect with multiple set to "yes" and the selections are "which columns of
> data do you want to see?"
Hopefully you are not using the raw form value directly in your sql, because that is a sql injection attack just waiting to happen.