Allo, it's worth keeping in mind variable names can be set dynamically
from thef left, ie;
<cfset "something_#i#_something.else" = "somevalue">
(I think)
On 10/28/08, Sean Coyne <[EMAIL PROTECTED]> wrote:
>
> so you want the conditions struct to have multiple keys
> answer1,answer2,answer3,etc and pollingobjectid
>
> <!--- create a struct to hold the arguments you will eventually pass
> in --->
> <cfset args = {} />
> <cfset args.conditions = {} />
> <cfset args.conditions.pollingobjectid = stobj.pollingobjectid />
> <cfset args.dsn = application.dsn />
>
> <!--- now do your loop --->
> <cfloop from="1" to="3" index="i">
>
> <!--- now i assume you are doing some logic to determine if answer & i
> should equal 1 or whatever --->
> <cfif something is True>
> <cfset args.conditions['answer' & i] = 1 />
> </cfif>
>
>
> </cfloop>
> <!--- now args contains the conditions and dsn values, conditions is a
> struct w/ a number of keys (answer1,2,3, etc so on and pollingobjectid
> --->
> <cfset result = obj.getMultipleByQuery(argumentCollection=args) />
>
> Hope this helps.
>
>
> On Oct 27, 8:43 am, Marco van den Oever <[EMAIL PROTECTED]>
> wrote:
>> Ok, what i want to do, and to use your example about the first code
>> piece:
>>
>> i want to give the struct with 2 keys (answer1 and pollingobjectid) a
>> i value in the 1 of the answer1 part, so in the loop i get:
>>
>> (answer1 and pollingobjectid)
>> (answer2 and pollingobjectid)
>> (answer3 and pollingobjectid)
>>
>> etc
>>
>> On Oct 27, 1:03 pm, Sean Coyne <[EMAIL PROTECTED]> wrote:
>>
>> > hmm. Not sure what you are asking.
>>
>> > In your first piece of code if i equals 3 after that code runs you
>> > will have a variable called variables.stprops.answer3.conditions and
>> > it will equal a struct with 2 keys (answer1 and pollingobjectid).
>>
>> > In your second piece of code you will have a variable called
>> > variables.answer3_sum and it will be a query.
>>
>> > As long as you are in a loop and the value of i changes, you will have
>> > variables created dynamically.
>>
>> > In order to call getMultipleByQuery your argumentCollection struct
>> > must have the dsn key and the conditions key.
>>
>> > On Oct 25, 2:59 pm, Marco van den Oever <[EMAIL PROTECTED]>
>> > wrote:
>>
>> > > Still don't know how to change the code below to also set the answer1
>> > > to something like answer & i, the answer1 needs to be dynamic
>> > > (answer1 / answer2 / answer 3 etc), is it possible? :
>>
>> > > <cfset variables.stprops['answer' & i].conditions =
>> > > {answer1='1',pollingobjectid=stobj.pollingobjectid} />
>>
>> > > and
>>
>> > > <cfset variables['answer' & i & '_sum'] =
>> > > obj.getMultipleByQuery(argumentCollection=stprops.answer1) />
>>
>> > > Thanks!
>>
>> > > On Oct 24, 11:13 pm, Marco van den Oever <[EMAIL PROTECTED]>
>> > > wrote:
>>
>> > > > Wow what a support :) Ok i now begin to see the structure of the
>> > > > structure, only thing i still not understand is how to set the
>> > > > answer1
>> > > > in:
>>
>> > > > <cfset variables.stprops['answer' & i].conditions =
>> > > > {answer1='1',pollingobjectid=stobj.pollingobjectid} />
>>
>> > > > <cfset variables['answer' & i & '_sum'] =
>> > > > obj.getMultipleByQuery(argumentCollection=stprops.answer1) />
>>
>> > > > to something as answer & i, as i can't cfset a struct or output a
>> > > > variable in that area, as i experience
>>
>> > > > On Oct 24, 9:00 pm, Sean Coyne <[EMAIL PROTECTED]> wrote:
>>
>> > > > > If I am reading correctly you want to do this (i added CF comments
>> > > > > explaining myself):
>>
>> > > > > <cfloop index="i" from="1" to="6">
>>
>> > > > > <cfif stprops_polling["answer" & i] GT 0> <!--- you dont need the
>> > > > > ##
>> > > > > and quotes around i --->
>>
>> > > > > <cfset variables.stprops['answer' & i] = {} /> <!--- this is fine
>> > > > > --->
>> > > > > <!--- you are setting .dsn in the key again. you to set it as a
>> > > > > struct. do this: --->
>> > > > > <cfset variables.stprops['answer' & i].dsn = application.dsn />
>> > > > > <!---
>> > > > > move .dsn outside --->
>> > > > > <cfset variables.stprops['answer' & i].conditions =
>> > > > > {answer1='1',pollingobjectid=stobj.pollingobjectid} /> <!--- same
>> > > > > things here, move .conditions out, and no need for ## and quotes
>> > > > > --->
>> > > > > <cfset variables['answer' & i & '_sum'] =
>> > > > > obj.getMultipleByQuery(argumentCollection=stprops.answer1) />
>> > > > > <!---
>> > > > > this will result in variables.answer1_sum and
>> > > > > variables.answer2_sum,
>> > > > > etc, as queries is this what you want? its fine if you do but I am
>> > > > > just checking. If you want to do answer1.sum or answer2.sum this
>> > > > > will
>> > > > > not work. --->
>>
>> > > > > <cfelse>
>>
>> > > > > <cfset variables['answer' & i & '_sum'].recordcount = 0> <!---
>> > > > > again,
>> > > > > setting a struct with the explicit key will set it as the key,
>> > > > > move
>> > > > > record count outside --->
>>
>> > > > > </cfif>
>>
>> > > > > </cfloop>
>>
>> > > > > Remember that whatever is within the brackets will be the KEY. If
>> > > > > you
>> > > > > want nested structures you need to use either another set of
>> > > > > brackets
>>
>> > > > > <cfset variables['structkey']['anotherstructkey'] = 'something' />
>> > > > > OR dot notation
>>
>> > > > > <cfset variables.structkey.anotherstructkey = 'something' />
>>
>> > > > > Perhaps explained better by:
>>
>> > > > > <cfset test = 'SOMEVALUE' />
>> > > > > <cfset variables['structKey_' & test].anotherstructkey =
>> > > > > 'something' /
>>
>> > > > > This will result in a struct called variables with a key called
>> > > > > 'structKey_SOMEVALUE' which is a struct with a key called
>> > > > > 'anotherstructkey'0
>>
>> > > > > But, If you do
>>
>> > > > > <cfset variables['structkey_' & test & '.anotherstructkey] =
>> > > > > 'something' />
>> > > > > this results in one struct called variables with a key called
>> > > > > 'structkey_SOMEVALUE.anotherstructkey'
>>
>> > > > > You see? The dot in the second example does not create another
>> > > > > struct. Its just another character in the key.
>>
>> > > > > Hope this helps
>>
>> > > > > Sean
>>
>> > > > > Sean
>>
>> > > > > On Oct 24, 2:49 pm, Marco van den Oever
>> > > > > <[EMAIL PROTECTED]>
>> > > > > wrote:
>>
>> > > > > > ahh ok so i was setting a structure named variables, great this
>> > > > > > solved
>> > > > > > the problem and the code looks very neat.
>> > > > > > one more question if i may, of course i now also want to update
>> > > > > > the
>> > > > > > other code to use looping instead of static, i really gave this
>> > > > > > a try
>> > > > > > but before i try stuff that just doesn't work, here it is:
>>
>> > > > > > p.s. the problem i have i understanding how to:
>>
>> > > > > > replace the " {answer1='1' " in <cfset
>> > > > > > variables.stprops['answer' & i
>> > > > > > & '.conditions'] =
>> > > > > > {answer1='1',pollingobjectid='#stobj.pollingobjectid#'} />
>>
>> > > > > > and how to
>>
>> > > > > > replace the " stprops.answer1 " in <cfset variables['answer' & i
>> > > > > > &
>> > > > > > '_sum'] =
>> > > > > > obj.getMultipleByQuery(argumentCollection=stprops.answer1) /
>>
>> > > > > > with the index value
>>
>> > > > > > <cfloop index="i" from="1" to="6">
>>
>> > > > > > <cfif stprops_polling["answer" & "#i#"] GT 0>
>>
>> > > > > > <cfset variables.stprops['answer' & i] = {} />
>> > > > > > <cfset variables.stprops['answer' & i & '.dsn'] =
>> > > > > > application.dsn />
>> > > > > > <cfset variables.stprops['answer' & i & '.conditions'] =
>> > > > > > {answer1='1',pollingobjectid='#stobj.pollingobjectid#'} />
>> > > > > > <cfset variables['answer' & i & '_sum'] =
>> > > > > > obj.getMultipleByQuery(argumentCollection=stprops.answer1) />
>>
>> > > > > > <cfelse>
>>
>> > > > > > <cfset variables['answer' & i & '_sum' & '.recordcount'] = 0>
>>
>> > > > > > </cfif>
>>
>> > > > > > </cfloop>
>>
>> > > > > > Thanks again!
>>
>> > > > > > On Oct 24, 7:44 pm, Sean Coyne <[EMAIL PROTECTED]> wrote:
>>
>> > > > > > > Oh. Now I see what you want to do. You want
>> > > > > > > stprops_pollingvote to
>> > > > > > > be a structure. So do this
>>
>> > > > > > > <cfset variables.stprops_pollingvote['answer' & i] = '1' />
>>
>> > > > > > > the stprops_pollingvote is the structure here. In the
>> > > > > > > previous one,
>> > > > > > > variables was the structure and "stprops_pollingvote.answer1"
>> > > > > > > was the
>> > > > > > > key.
>>
>> > > > > > > You want variables.stprops_pollingvote and have "answer1" as
>> > > > > > > the key
>>
>> > > > > > > Sean
>>
>> > > > > > > On Oct 24, 9:46 am, Marco van den Oever
>> > > > > > > <[EMAIL PROTECTED]>
>> > > > > > > wrote:
>>
>> > > > > > > > Tomek thanks, when i use evaluate like:
>>
>> > > > > > > > <cfloop index="i" from="1" to="6">
>>
>> > > > > > > > <cfif #form[stprops_polling.objectid]# EQ "#i#">
>>
>> > > > > > > > <cfset evaluate("stprops_pollingvote.answer" & "#i#") = "1">
>>
>> > > > > > > > </cfif>
>>
>> > > > > > > > </cfloop>
>>
>> > > > > > > > i get an error:
>>
>> > > > > > > > 15:40:31.031 - Template Exception - in
>> > > > > > > > C:\Inetpub\wwwroot\farcry\core
>> > > > > > > > \packages\rules\rules.cfc : line 133
>>
>> > > > > > > > Cannot assign a value to a function.
>>
>> > > > > > > > Sean, also thanks, when i use your suggestion:
>>
>> > > > > > > > <cfloop index="i" from="1" to="6">
>>
>> > > > > > > > <cfif #form[stprops_polling.objectid]# EQ "#i#">
>>
>> > > > > > > > <cfset variables[ "stprops_pollingvote.answer" & i ] = "1">
>>
>> > > > > > > > </cfif>
>>
>> > > > > > > > </cfloop>
>>
>> > > > > > > > the structure not gets the value assigned, when i use this:
>>
>> > > > > > > > <cfif #form[stprops_polling.objectid]# EQ "1">
>> > > > > > > > <cfset stprops_pollingvote.answer1 = "1">
>> > > > > > > > <cfelseif #form[stprops_polling.objectid]# EQ "2">
>> > > > > > > > <cfset stprops_pollingvote.answer2 = "1">
>> > > > > > > > <cfelseif #form[stprops_polling.objectid]# EQ "3">
>> > > > > > > > <cfset stprops_pollingvote.answer3 = "1">
>> > > > > > > > <cfelseif #form[stprops_polling.objectid]# EQ "4">
>> > > > > > > > <cfset stprops_pollingvote.answer4 = "1">
>> > > > > > > > <cfelseif #form[stprops_polling.objectid]# EQ "5">
>> > > > > > > > <cfset stprops_pollingvote.answer5 = "1">
>> > > > > > > > <cfelseif #form[stprops_polling.objectid]# EQ "6">
>> > > > > > > > <cfset stprops_pollingvote.answer6 = "1">
>> > > > > > > > </cfif>
>>
>> > > > > > > > it works fine, and although the structure is the same in
>> > > > > > > > output, in
>> > > > > > > > code view it's of course more neat to have it in a loop.
>>
>> > > > > > > > So just leave it like this or is it possible to do so in a
>> > > > > > > > loop??
>>
>> > > > > > > > Thanks both!
>>
>> > > > > > > > On Oct 24, 2:06 pm, Sean Coyne <[EMAIL PROTECTED]> wrote:
>>
>> > > > > > > > > dont use evaluate. Try:
>>
>> > > > > > > > > <cfset i = '1' />
>> > > > > > > > > <cfset variables[ "stprops_pollingvote.answer" & i ] =
>> > > > > > > > > "1">
>> > > > > > > > > <cfdump var="#variables#" />
>>
>> > > > > > > > > just worked for me. What is "i" set to?
>>
>> > > > > > > > > On Oct 23, 9:38 pm, "Tomek Kott" <[EMAIL PROTECTED]>
>> > > > > > > > > wrote:
>>
>> > > > > > > > > > i think something like
>> > > > > > > > > > <cfset evaluate("stprops_pollingvote.answer" & "#i#") =
>> > > > > > > > > > "1"> might work. If
>> > > > > > > > > > that doesn't, I think generally you need to use evaluate
>> > > > > > > > > > for something like
>> > > > > > > > > > that. That's the only way I can think of to get
>> > > > > > > > > > something like that done
>> > > > > > > > > > though.
>>
>> > > > > > > > > > Best,
>>
>> ...
>>
>> read more ยป
> >
>
--
Sent from Gmail for mobile | mobile.google.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"farcry-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/farcry-dev?hl=en
-~----------~----~----~----~------~----~------~--~---