Dollique
Dollique

Reputation: 1012

coldfusion: use string as structname

I didn't find an answer to this question because I don't know if I'm expressing the problem correctly.

It's quite simple. I have this code:

<cfset queryAddRow(sday.morning) />

and I need something like this instead:

<cfset tday = "morning" />
<cfset queryAddRow(sday.tday) />

Is there any easy way to do this?

Upvotes: 0

Views: 78

Answers (1)

azawaza
azawaza

Reputation: 3084

Assuming sday.morning is a query, then you can use associative array notation to reference the key dynamically:

struct[key]

where 'key' is a variable holding name of the key. In your case the code to use would be:

queryAddRow(sday[tday])

Upvotes: 4

Related Questions