Skip to main content
Known Participant
May 10, 2012
Question

Dynamic vars in cfloop have the same value

  • May 10, 2012
  • 2 replies
  • 604 views

Hi All,

I'm fooling around with the Google API's and am trying to output the result of a CFHTTP call for each user found in a db table. My code seems to process ok...no errors but the value of the two variables I'd expect to exist are the same. I'm sure I'm doing something silly in the loop that messing it up. Any thoughts?

<cfloop query = "getTokens"> 

    <cfhttp url="https://www.googleapis.com/latitude/v1/currentLocation" result="#tokName#">

        <cfhttpparam type="header" name="Authorization" value="OAuth #application.token.access_token#" >

        <cfhttpparam type="url" name="granularity" value="best" >

    </cfhttp>

   

    <cfset "apidata#tokName#" = #DeserializeJSON( evaluate("#tokName#.FileContent") )#>

</cfloop>

Thx!

PS - Also, how to you CFDUMP a dynamically named var such as the one created in the code above?

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    May 11, 2012

    You could simplify it as follows:

    <cfset apidata = arrayNew(1)>

    <cfloop query = "getTokens"> 

        <cfhttp url="https://www.googleapis.com/latitude/v1/currentLocation" result="arbitraryName">

            <cfhttpparam type="header" name="Authorization" value="#getTokens.query_column_name_representing_auth#" >

            <cfhttpparam type="url" name="granularity" value="best" >

        </cfhttp>

       

        <cfset apidata[getTokens.currentrow] = deserializeJSON(arbitraryName.FileContent)>

    </cfloop>

    Inspiring
    May 11, 2012

    use array notation to dump dynamically named variables.  #variables["static_part" & variable_part]#