>I think I made that rather confusing. > >Output needs to be > ><p>Value 1 = Green</p> ><p>Value 2 - Something else</p> ><p>........ > >So for database fields "MyField1_a", "MyField2_a", "MyField3_a" ... >
I think what is confusing people is that you aren't quite clear exactly what you are trying to do. I have a feeling that whatever you are trying to do, you will be able to accomplish it by using a dynamic value as a hash key: If you are working with standard variables, then you can access them using the Variables hash. If it is a value assigned by a URL/FORM, you will need to use the URL or FORM hashes instead, but here is an example. <cfset fish = "Salmon"> <cfset fight = ArrayNew(1)> <cfset fight[1] = "Tyson"> <cfset fight[2] = "Ali"> <cfset letters = "fi"> <cfoutput> #Variables[letters & "sh"]# </cfoutput> The output will display "Salmon" which is the value of the variable "fish" Now let's say you wanted "Tyson" to come up.. you CAN'T reference it as you might be tempted to: <cfoutput> #Variables[letters & "ght[1]"]# </cfoutput> This will NOT work, because "fight[1]" is not a valid key in the "Variable" hash... the actual key is "fight", and it contains an array of two values... so you would have to reference it like: <cfoutput> #Variables[letters & "ght"][1]# </cfoutput> So, in essence, you get Variables["fight"][1], which basically is the same as just fight[1], but you were able to get the value in an indirect way :) If you need the entire thing to be dynamic, you could use evaluate: <cfset letters="fi"> <cfset number = 2> <cfoutput> #Evaluate(letters & "ght"][" & number & "]")# </cfoutput> Though, whenever possible, I would lean away from evaluate and more towards something like: <cfset letters="fi"> <cfset number = 2> <cfoutput> #Variables[letters & "ght"][number]# </cfoutput> If it is a SQL Query, then you are in for a slightly more difficult time. Query results are very close in implementation to hashes, with each hash value containing an array of results, one entry for each query result... for instance: myQuery.FirstName[1] (contains FirstName value of first query result) myQuery.FirstName[2] (contains FirstName value of second query result) myQuery.FirstName[3] (contains FirstName value of third query result) myQuery.LastName[1] (contains LastName value of first query result) myQuery.LastName[2] (contains LastName value of second query result) myQuery.LastName[3] (contains LastName value of third query result) But, within a query output loop, you can't just say myQuery["LastName"], because that ends up being the entire array of those values, which isn't what you want. Fortunately, during the loop, the "currentrow" value will hold the correct location of your current data, so you can do something like: <cfset NameType = "First"> <cfoutput query="myQuery"> #myQuery[NameType & "Name"][myQuery.currentrow]#<br> </cfoutput> Which would output the FirstName column for each row.. Anyway, hope this helped you some :) -- Pat ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Upgrade to Adobe ColdFusion MX7 Experience Flex 2 & MX7 integration & create powerful cross-platform RIAs http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:268271 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4