5 Replies - 939 Views - Last Post: 02 August 2011 - 08:53 AM Rate Topic: -----

Topic Sponsor:

#1 sattua  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 82
  • Joined: 20-March 08

unknown iteration in cfoutput

Posted 28 July 2011 - 10:56 AM

hi well i fixed the problem already but I did not found what was wrong, so I'll explain:

i have this cfcomponent, this one:

<cfcomponent displayname="participation_validator" hint="participation in n number of weeks per user">
	
	 <cffunction name="getWeekPerUser" hint="Gets all weeks where a user has played" returntype="numeric">

		<cfargument name="usernid" type="string" required="yes">
		
	   	<cfquery name="getWeekPerUserQuery" datasource="capperscorner" >
		 	select distinct count(week) as nweeks from tablex where account = '#usernid#'
	   	</cfquery>
	
		
	   	<cfreturn getWeekPerUserQuery.nweeks[1]>
	
	 </cffunction>

</cfcomponent>




it's simple, it just return a numeric, this componet is invoke by this code(the whole cfm file is too big, so this is a part):

			<td align="center">
				<cfinvoke component="participation_validator"
					method="getWeekPerUser"
					returnvariable="weekscount">
					
			   		<cfinvokeargument name="usernid" value=#account#>
			   		
				</cfinvoke>
				<cfoutput>#weekscount#</cfoutput>
			</td>





so the problem was that the #weekscount# value into the <cfoutput> tag, printed many times (like in a loop), no idea why, so what I did was take out the #weekscount# value from the <cfoutput> tag, and as I expected, the value only printed once.

The question is; why when the value was into the tag, this one got printed many times? i thought at first "maybe theres a loop somewhere", but when I took the value outside the tag,everything works ok

thx in advance

This post has been edited by sattua: 28 July 2011 - 10:58 AM


Is This A Good Question/Topic? 0
  • +

Replies To: unknown iteration in cfoutput

#2 Craig328  Icon User is online

  • I make this look good
  • member icon

Reputation: 1101
  • View blog
  • Posts: 2,607
  • Joined: 13-January 08

Re: unknown iteration in cfoutput

Posted 28 July 2011 - 11:31 AM

I'm having trouble understanding what you did here:

Quote

so the problem was that the #weekscount# value into the <cfoutput> tag, printed many times (like in a loop), no idea why, so what I did was take out the #weekscount# value from the <cfoutput> tag, and as I expected, the value only printed once


If you can post the code example where you "take out the #weekscount# value from the <cfoutput> tag" that you say ran okay, maybe we can figure it out. From the way you describe it, if you removed the variable from in between the cfoutput tags, nothing should have outputted.

Further, why are your component method returning "getWeekPerUserQuery.nweeks[1]"? Your getWeekPerUserQuery should return a single value as it is an aggregate function value, right? I see you have a distinct in there so maybe I'm a little confused about what you're trying to return with the array notation.
Was This Post Helpful? 0
  • +
  • -

#3 sattua  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 82
  • Joined: 20-March 08

Re: unknown iteration in cfoutput

Posted 28 July 2011 - 12:11 PM

hi thx for reply.

yeah sure, i take out the #weekscount# value from the <cfoutput> tag, I put it like this:


			<td align="center">
				<cfinvoke component="participation_validator"
					method="getWeekPerUser"
					returnvariable="weekscount">
					
			   		<cfinvokeargument name="usernid" value=#account#>
			   		
				</cfinvoke>

				#weekscount#
			
			</td>


this works good. the #weekscount# value prints well. About the componet, well it doesn't matter how it works coz return what I need to get.

In summary : only:
#weekscount#
works ok,
<cfoutput>#weekscount#</cfoutput> 
iterates n number of times.
Was This Post Helpful? 0
  • +
  • -

#4 Craig328  Icon User is online

  • I make this look good
  • member icon

Reputation: 1101
  • View blog
  • Posts: 2,607
  • Joined: 13-January 08

Re: unknown iteration in cfoutput

Posted 28 July 2011 - 12:50 PM

If the weekscount is outputting then you have cfoutputs bracketing that code section somewhere. You mentioned what you posted was just a portion because the rest of the page was too big to post. Go to the top of the page and do a ctrl-f (normal shortcut for a Find function) and look for cfoutput.
Was This Post Helpful? 0
  • +
  • -

#5 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: unknown iteration in cfoutput

Posted 01 August 2011 - 09:17 AM

It sounds like you definitely have a <cfoutput query="x" group="y"> somewhere in your code. To better explain what is happening, I will give you an example of a cfoutput loop.

<cfquery name="availableDates">
    SELECT date,month FROM availabledates ORDER BY month
</cfquery>
<select name="dates">
    <cfoutput query="availableDates" group="month">
        <optgroup>#availableDates.month#"</optgroup>
        <cfoutput>
            <option value="#availableDates.date#">#availableDates.date#"</option>
        </cfoutput>
    </cfoutput>
</select>



So what happens is that one loop gives me the month name as an option group. Then I use a nested cfoutput tag to loop through all the values in that month. Using any other nested cfoutput should throw an error so if you are using Eclipse do a regex find of cfoutput([A-Za-z0-9\"\ \=]+)(group=("|')[fdsa]+("|')) and that should find you the grouped cfoutput.
Was This Post Helpful? 1
  • +
  • -

#6 sattua  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 82
  • Joined: 20-March 08

Re: unknown iteration in cfoutput

Posted 02 August 2011 - 08:53 AM

thanks Craig328, xheartonfire43x; for reply, i will take your advices ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1