House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Question about looping and the first row in a column

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Andy,
Ben Nadel
02/23/07 11:51 A
Andy Matthews wrote:
Jim Wright
02/23/07 11:57 A
Andy,
Ben Nadel
02/23/07 12:22 P
Thanks Ben...
Andy Matthews
02/23/07 12:34 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Andy Matthews
02/23/2007 11:42 AM

I'm sure that other people have run into this, but I'm baffled as to why this is happening. I have a query in the variables scope (VARIABLES.GetThisNavigationLocation). I'm looping over this query just like you would normally. Then, inside that loop, I'm looping over another query (VARIABLES.getChangeFrequencies) to build a dynamic dropdown. So for each row in GetThisNavigationLocation, there's a dropdown containing every row in getChangeFrequencies. The problem is that inside the dropdown loop, the cfif seems to be using the value from the very first row in the outer query in it's comparison which results in every dropdown showing the same value, even though when I dump the outer query, the values are clearly different. <cfloop query="VARIABLES.getChangeFrequencies"> <option value="#VARIABLES.getChangeFrequencies.ID#" <cfif VARIABLES.GetThisNavigationLocation.changefreq EQ VARIABLES.getChangeFrequencies.ID>selected</cfif>>#VARIABLES.getChangeFreque ncies.DisplayName#</option> </cfloop> The weird thing comes when I set a temp variable just outside the dropdown loop like so: <cfset tempFreq = VARIABLES.GetThisNavigationLocation.changefreq> When I use that code, and compare to "tempFreq", the code works just fine. Why is this happening? Does anyone have wisdom on this because it's really irritating for me to have to have this extra line of code in here. Anyone? ____________________________________ Andy Matthews Senior Coldfusion Developer Office:  877.707.5467 x747 Direct:  615.627.9747 Fax:  615.467.6249 amatthews@dealerskins.com www.dealerskins.com <http://www.dealerskins.com/>;

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Adrian Lynch
02/23/2007 11:48 AM

Yaaaaarp, that's been around for a while. You're using the fix everyone else does. Adrian I'm sure that other people have run into this, but I'm baffled as to why this is happening. I have a query in the variables scope (VARIABLES.GetThisNavigationLocation). I'm looping over this query just like you would normally. Then, inside that loop, I'm looping over another query (VARIABLES.getChangeFrequencies) to build a dynamic dropdown. So for each row in GetThisNavigationLocation, there's a dropdown containing every row in getChangeFrequencies. The problem is that inside the dropdown loop, the cfif seems to be using the value from the very first row in the outer query in it's comparison which results in every dropdown showing the same value, even though when I dump the outer query, the values are clearly different. <cfloop query="VARIABLES.getChangeFrequencies"> <option value="#VARIABLES.getChangeFrequencies.ID#" <cfif VARIABLES.GetThisNavigationLocation.changefreq EQ VARIABLES.getChangeFrequencies.ID>selected</cfif>>#VARIABLES.getChangeFreque ncies.DisplayName#</option> </cfloop> The weird thing comes when I set a temp variable just outside the dropdown loop like so: <cfset tempFreq = VARIABLES.GetThisNavigationLocation.changefreq> When I use that code, and compare to "tempFreq", the code works just fine. Why is this happening? Does anyone have wisdom on this because it's really irritating for me to have to have this extra line of code in here. Anyone? ____________________________________ Andy Matthews

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Nadel
02/23/2007 11:51 AM

Andy, I think that's just the nature of the beast. ColdFusion has to keep some sort of internal model going for it's loops and when the get nested, I think things get a bit screwy. You might be able to accurately use the Current Row value: <cfloop query="qINNERLoop"> #qOuterLoop[ "id" ][ qOuterLoop.CurrentRow ]# #qINNERLoop.id# </cfloop> A bit more verbose, but I think I heard that works. ..................... Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ I'm sure that other people have run into this, but I'm baffled as to why this is happening. I have a query in the variables scope (VARIABLES.GetThisNavigationLocation). I'm looping over this query just like you would normally. Then, inside that loop, I'm looping over another query (VARIABLES.getChangeFrequencies) to build a dynamic dropdown. So for each row in GetThisNavigationLocation, there's a dropdown containing every row in getChangeFrequencies. The problem is that inside the dropdown loop, the cfif seems to be using the value from the very first row in the outer query in it's comparison which results in every dropdown showing the same value, even though when I dump the outer query, the values are clearly different. <cfloop query="VARIABLES.getChangeFrequencies"> <option value="#VARIABLES.getChangeFrequencies.ID#" <cfif VARIABLES.GetThisNavigationLocation.changefreq EQ VARIABLES.getChangeFrequencies.ID>selected</cfif>>#VARIABLES.getChangeFr eque ncies.DisplayName#</option> </cfloop> The weird thing comes when I set a temp variable just outside the dropdown loop like so: <cfset tempFreq = VARIABLES.GetThisNavigationLocation.changefreq> When I use that code, and compare to "tempFreq", the code works just fine. Why is this happening? Does anyone have wisdom on this because it's really irritating for me to have to have this extra line of code in here. Anyone? ____________________________________ Andy Matthews Senior Coldfusion Developer Office:  877.707.5467 x747 Direct:  615.627.9747 Fax:  615.467.6249 amatthews@dealerskins.com www.dealerskins.com <http://www.dealerskins.com/>;

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jim Wright
02/23/2007 11:57 AM

Andy Matthews wrote: >   > When I use that code, and compare to "tempFreq", the code works just fine. > Why is this happening? Does anyone have wisdom on this because it's really > irritating for me to have to have this extra line of code in here. Anyone? >   I think about the best answer you are going to get is "because that is the way it is".  It is kind of a rite of passage for CF developers when they realize that one. One thing I would look into, though, is whether you can re-write your queries to use a single query, and then use cfoutput with the "group" attribute.  That will proably result in some cleaner looking code.  Most likely faster, too.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Nadel
02/23/2007 12:22 PM

Andy, The way to do it without creating temp variables: http://bennadel.com/index.cfm?dax=blog:546.view ..................... Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ Andy Matthews wrote: >   > When I use that code, and compare to "tempFreq", the code works just fine. > Why is this happening? Does anyone have wisdom on this because it's > really irritating for me to have to have this extra line of code in here. Anyone? >   I think about the best answer you are going to get is "because that is the way it is".  It is kind of a rite of passage for CF developers when they realize that one. One thing I would look into, though, is whether you can re-write your queries to use a single query, and then use cfoutput with the "group" attribute.  That will proably result in some cleaner looking code.  Most likely faster, too.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Andy Matthews
02/23/2007 12:34 PM

Thanks Ben... I'll take a look at that in a little bit! Andy, The way to do it without creating temp variables: http://bennadel.com/index.cfm?dax=blog:546.view ...................... Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ Andy Matthews wrote: >   > When I use that code, and compare to "tempFreq", the code works just fine. > Why is this happening? Does anyone have wisdom on this because it's > really irritating for me to have to have this extra line of code in here. Anyone? >   I think about the best answer you are going to get is "because that is the way it is".  It is kind of a rite of passage for CF developers when they realize that one. One thing I would look into, though, is whether you can re-write your queries to use a single query, and then use cfoutput with the "group" attribute.  That will proably result in some cleaner looking code.  Most likely faster, too.


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 20, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference