3

I'm going through a query in which there are 12 entries named "choice_1" through "choice_12." I want to be able to dynamically call an individual choice depending where it is in the loop. So here is the query:

<CFQUERY DATASOURCE="tr3" NAME="qryUserMatchPref"> 
    SELECT *
FROM UsrMatchPrefTR2
WHERE session = #sess# AND site = #siteFirst# AND user_id = #tempUser#
</CFQUERY>

And let's say the loop is on it's third run and I wanted to check choice_3, I would want in theory to do something like this.

<cfset combined = "choice_" & counterChoice>
<cfset tempMatch = qryUserMatchPref.#combined#>

I would of course be querying for choice_3, if counterChoice is equal to 3, and not for what ever is in the "combined" column [doesn't exist in this case]. Is there a way to do this in coldfusion or am I doomed to create a very tedious series of if statements? D:

Anthony Tantillo
  • 300
  • 1
  • 3
  • 12

1 Answers1

10

you should just be able to do

qryUserMatchPref[combined][currentRow]
Dale Fraser
  • 4,623
  • 7
  • 39
  • 76
  • And if your query only returns one record and your not looping over it you can just change [currentRow] to [1] – Dale Fraser Jan 17 '12 at 02:34
  • Wow, this is perfect and exactly what I was looking for, though I personally had no need for the [currentRow]. Thank you for the speedy response. :) **And than I read your comment and you already explained that. Thank you again. :D** – Anthony Tantillo Jan 17 '12 at 02:48