Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dynamic vars in cfloop have the same value

New Here ,
May 10, 2012 May 10, 2012

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?

575
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 10, 2012 May 10, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2012 May 11, 2012
LATEST

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources