2

I am pulling my hair out working on what would seem to be easy problem. But as a ColdFusion rookie I am just having a hell of a time figuring it out.

<cfoutput query="getSeasonAndRate">
    <cfset adultRate = groupRate>
</cfoutput>

So ... adultRate = 89

<cfset adultRate = 88>

So why does adultRate STILL equal 89?

Thanks! :D

Mitchell
  • 313
  • 5
  • 14

2 Answers2

4

It could be a scoping issue, try this:

<cfset variables.adultRate= 0>
<cfoutput query="getSeasonAndRate">
    <cfset variables.adultRate = getSeasonAndRate.groupRate>
</cfoutput>
<cfdump var="#variables.adultRate#">

It could also be that the query is returning more than one result, trying dumping out what is in that query like this:

<cfdump var="#getSeasonAndRate#">
Stefano D
  • 958
  • 5
  • 17
1

If your query contains a column named "adultRate" then your CFSET statement is updating the query object, not the variables scope.

This page (disclosure: on my own blog) discusses scope priority when reading and writing variables without explicitly specifying scope.

To fix your problem, change:

<cfset adultRate = groupRate>

to:

<cfset variables.adultRate = getSeasonAndRate.groupRate>

(assuming the groupRate value you want to get the value from is part of the query)

Adam Tuttle
  • 19,505
  • 17
  • 80
  • 113
  • Not sure you're justified in voting Adam's answer down considering the fact that both answers say "answered 1 hour ago". He probably answered it at the same time you did, which just means he's as smart as you are, not that he took your answer :). – Dan Short Mar 01 '11 at 19:55
  • 1
    @Dan - I see "1 hour ago for" Adam and "2 hours ago" for this Stefano chap. – Brian David Berman Mar 01 '11 at 19:57
  • I feel that my answer added a significant amount of additional clarity (about scope priorities), making it worth posting my own answer. Sorry you didn't like it, @Stefano, but that's just the way the game is played. – Adam Tuttle Mar 01 '11 at 20:31
  • Odd @Brian, I'm still seeing matching times for both. Would be nice if SO would show the exact time an answer was posted. – Dan Short Mar 01 '11 at 20:39
  • @Dan - It does, mouse over the "N hours ago". @Stefano was at 17:55:03Z and @Adam was at 18:16:01Z. – Brian David Berman Mar 01 '11 at 20:56
  • The best written, most helpful answer should be selected as the accepted answer, even if it is written a year after another similar answer. – Adam Tuttle Mar 01 '11 at 22:15