Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFLOOP within grouped CFOUTPUT not working 1

Status
Not open for further replies.

xsw1971

Programmer
Jun 21, 2001
153
US
A job can have multiple "time" entries associated with it. Each job/time combination is a record in the database.

The following code generates a row for every job returned from my query, and a column is generated for each "time" entry. This works just fine; all of my jobs and their times display.

Code:
<cfoutput query=&quot;myQuery&quot; group=&quot;job&quot;>
<tr>
  <td>#job#</td>
  <cfoutput>
  <td>#time#</td>
  </cfoutput>
</tr>
</cfoutput>


I am trying to add a CFLOOP within the CFOUTPUT tags that will generate 7 columns, one for each day of the week. As I'm outputting the time for each job, I am making it display on the proper day of the week. It works fine for the first record returned, but I can't repeat the inner loop in subsequent iterations of the first output. (It displays multiple rows, with the job number listed, but it won't loop through and display their hours). The code is below.

Code:
<cfoutput query=&quot;myQuery&quot; group=&quot;job&quot;>
<tr>
  <td>#job#</td>
  <!--- print a cell for each day of the week --->
  <cfloop index=&quot;countDays&quot; from=&quot;1&quot; to=&quot;7&quot;>
  <td>
    <!--- dayVar is a variable previously generated --->
    <input type=&quot;Hidden&quot; value=&quot;#DateFormat(DateAdd('WW', -1, dayVar), &quot;mmddyy&quot;)#&quot;></input>
    <!--- if there was time worked for that day, print the hours --->
    <cfoutput>
      <cfif DateFormat(#date_worked#, &quot;mmddyy&quot;) EQ  DateFormat(DateAdd('WW', -1,#dayVar#), &quot;mmddyy&quot;)>
        #time#
      </cfif>
    </cfoutput>
    <cfset dayVar = DateFormat(DateAdd('D', 1, dayVar), 'mm/dd/yy')>
  </td>
  </cfloop>
</tr>
</cfoutput>

I may just be confused on how loop and output work together. Any help is greatly appreciated.

Jennie
 
I would check what is exactly that you are getting from looping &quot;myQuery&quot;; fact that you have the result for the first row tells you that you have some result to work with, but what is that second row looks like? try to comment the loop and output the values such as &quot;date_worked&quot; and &quot;dayVar&quot; to make sure that you are getting the values that you want to work with;

also, this will be more efficient (no need for cfoutput when this is used within cfoutput that you are using to output &quot;myQuery&quot;):
<cfif DateFormat(date_worked, &quot;mmddyy&quot;) EQ DateFormat(DateAdd('WW', -1, dayVar), &quot;mmddyy&quot;)>
#time#
</cfif>




Sylvano
dsylvano@hotmail.com
 
I'm getting the results I want from the first cfoutput. Each row is a distinct job, and each of the following columns is a time entry for that job.

What I'm trying to accomplish with the second cfoutput (and the cfloop) is to display the time on Monday if it was entered on Monday, display it on Tuesday if it was entered on Tuesday, etc. The debugger shows that the number of records returned is accurate, they just won't display.

cfoutput has to be nested in cfoutput if you want to group records and display all of their values. If you don't nest the cfoutput you'll only get the first record.

For example, if you have the following records:
Jane, dog
Jane, cat
Jane, bird
John, fish
John, lizard

And you use the first code of mine above:
Code:
<cfoutput query=&quot;myQuery&quot; group=&quot;name&quot;>
<tr>
  <td>#name#</td>
  <cfoutput>
  <td>#pet#</td>
  </cfoutput>
</tr>
</cfoutput>

you'll get the following results:
Jane dog cat bird
John fish lizard

Without the nested cfoutput, you only get:
Jane dog
John fish


So I'm back to my initial question - why won't the first query interate after the inner loop has finished?
 
this code worked for me; see if you can use it; :)


<cfoutput query=&quot;request.aqTemplates&quot; group=&quot;PARENT&quot;>
<cfif NOT ListFind(&quot;none,Main Menu&quot;, PARENT)>
<cfset variables.tempParent = PARENT>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; style=&quot;border:1px solid Gray;&quot;>
<tr>
<td colspan=&quot;3&quot; bgcolor=&quot;##c0c0c0&quot; style=&quot;padding-left:10px; padding-top:5px; padding-bottom:5px; border-top:1 Solid White; border-right:1 Solid White; border-left:1 Solid Black; border-bottom:1 Solid Black;&quot;>
<cfloop from=&quot;1&quot; to=&quot;#request.aqTemplates.recordCount#&quot; index=&quot;i&quot;>
<cfif request.aqTemplates.Parent EQ variables.tempParent>
<a href=&quot;JavaScript:setHref('shared','#request.aqTemplates.FileID#');&quot;>#request.aqTemplates.Link# #i#</a><br>
</cfif>
</cfloop>
</td>
</tr>
</table>
</cfif>
</cfoutput> Sylvano
dsylvano@hotmail.com
 
=== START CODE EXAMPLE ===
<cfset dayVar = &quot;6/30/2002&quot;>

<cfoutput query=&quot;myQuery&quot; group=&quot;job&quot;>
[COLOR=666666]<!--- 1st Time: dayVar=6/30/2002 - job=&quot;job1&quot; --->[/color]
[COLOR=666666]<!--- 2nd Time: dayVar=7/7/2002 - job=&quot;job2&quot; --->[/color]
[COLOR=666666]<!--- 3rd Time: dayVar=7/14/2002 - job=&quot;job3&quot; --->[/color]

<cfloop index=&quot;countDays&quot; from=&quot;1&quot; to=&quot;7&quot;>
<cfoutput></cfoutput>
[COLOR=666666]<!--- Incrememnt Date by one day --->[/color]
<cfset dayVar = DateAdd...>
</cfloop>
</cfoutput>
=== END CODE EXAMPLE ===

The solution would be to set the date inside the
<cfoutput query=&quot;&quot;...>

=== START CODE EXAMPLE ===
<cfoutput query=&quot;myQuery&quot; group=&quot;job&quot;>
<cfset dayVar = &quot;6/30/2002&quot;>
[COLOR=666666]<!--- 1st Time: dayVar=6/30/2002 - job=&quot;job1&quot; --->[/color]
[COLOR=666666]<!--- 2nd Time: dayVar=6/30/2002 - job=&quot;job2&quot; --->[/color]
[COLOR=666666]<!--- 3rd Time: dayVar=6/30/2002 - job=&quot;job3&quot; --->[/color]

<cfloop index=&quot;countDays&quot; from=&quot;1&quot; to=&quot;7&quot;>
<cfoutput></cfoutput>
[COLOR=666666]<!--- Incrememnt Date by one day --->[/color]
<cfset dayVar = DateAdd...>
</cfloop>
</cfoutput>
=== END CODE EXAMPLE === - tleish
 
Some of my message on the last post got lost. The first example shows that the current way the script is set up, it will check one week and one week only. So for Job one, it would check week 1, and for job 2, it wouldn't check week one, but week 2...etc.

My thinking is the issue is with setting the dayVar variable.

The 2nd example is where I think dayVar should be set. - tleish
 
Wow, tleish, that was amazing! I've been working on this for almost a week and was focusing on the wrong thing - it works great now!!! THANK YOU!

I have to ask, though, what made you think that dayVar was incrementing a week every time the query iterated? I don't have any code that makes it increment by a week...

Jennie

PS - how did you make the code colored? It's much easier to read that way.

PPS - WWebSpider, thanks for the input - I didn't get a chance to try it though (tleish's suggestion was much quicker!)
 
I knew that it was being incremented by a week because of the <cfloop>. Since the <cfloop> incremented dayVar by one day, after the <cfloop> complete the 7 reps, dayVar was now 7 days later, or one week later. If the day wasn't reset then it would just keep incrementing from there.

=== START CODE EXAMPLE ===
Code:
[COLOR=MAROON]<cfloop index=[COLOR=BLUE]&quot;countDays&quot;[/color] from=[COLOR=BLUE]&quot;1&quot;[/color] to=[COLOR=BLUE]&quot;7&quot;[/color]>[/color]
	[COLOR=MAROON]<cfoutput>[/color][COLOR=MAROON]</cfoutput>[/color]
	[B][COLOR=666666][I]<!--- Incrememnt Date by one day --->[/I][/color][/B]
	[b][COLOR=MAROON]<cfset dayVar = DateAdd...>[/color][/b]
[COLOR=MAROON]</cfloop>[/color]
=== END CODE EXAMPLE ===

TGML Parser
The color coding comes from a cfml script I wrote that color codes CFML, HTML, and JavaScript to look similar to the formatting of ColdFusion Studio / Homesite default color coding using TekTips TGML formating.

see:
I write the message and code I want, send it through my TGML parser, and post it to the forum.

- tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top