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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop Problem

Status
Not open for further replies.

susanh

MIS
Jan 16, 2001
229
US
Good Morning,

I know that i just have the syntax wrong on my code, but I can't tell what I am doing wrong. When I run the page, I get the email 25 times, as I have 5 records in the database.

Help :) Thanks Sue

My Code:
<cfquery name="tickler" datasource="Intranet">
Select ID, ProjectID, TaskID, Name, Customer, Unit, NonEESUnit, description, Startdate
From Tasks
Where StartDate <= #CreateODBCDate(DateAdd("d", -1, Now()))# AND Status = 'Open' AND Assigned = 'bwoods'
Order By TaskID
</cfquery>
</head>
<body>
<!---then sends a tickler email to tech--->
<cfloop query="tickler">
<cfif IsDefined("tickler.StartDate")>
<cfoutput query="tickler" group="id">
<cfmail
From="shigman@emeraldscreening.com"
To="shigman@emeraldscreening.com"
Subject="Task is still open">

This is a quick, computer-generated email sent to
remind you of that the following Task is still open. Please update.

Repair Order: #tickler.projectID#
Task Number: #tickler.taskid#
Customer: #tickler.customer#
Name: #tickler.name#
Unit: #tickler.unit#
Non Emerald Unit: #tickler.noneesunit#
Description: #tickler.description#
Start Date: #Dateformat(tickler.startdate, 'MM/DD/YY')#


Please Advise.
</cfmail>
</cfoutput>
</cfif>
</cfloop>
 
i think you can just safely remove the CFLOOP altogether

and replace your CFIF with this --

<cfif tickler.RecordCount >

the CFOUTPUT will loop through the query's result set because you're using the QUERY= parameter

more than just identifying the scope for any variables within the CFQUERY, the QUERY= paramater actually performs the looping

:)



r937.com | rudy.ca
 
susanh,

Its the nested looping thats generating 25 emails. (5 rows outer loop x 5 rows inner loop)

<!--- outer loop --->
<cfloop query="tickler">
<!--- inner loop --->
<cfoutput query="tickler" group="id">
</cfoutput>
</cfloop>

r937's correct. If you want to generate one email for each record in the query, just use the query attribute. If you want to generate only (1) email containing all of the results

Code:
<cfif tickler.recordCount gt 0>

<cfmail
  From="shigman@emeraldscreening.com"
  To="shigman@emeraldscreening.com"
  Subject="Task is still open">
  
  This is a quick, computer-generated email sent to
  remind you of that the following Task is still open.  Please update.
  <cfloop query="tickler">
  Repair Order: #tickler.projectID#
  Task Number:  #tickler.taskid#
  Customer: #tickler.customer#
  Name:  #tickler.name#
  Unit: #tickler.unit#
  Non Emerald Unit: #tickler.noneesunit#
  Description:  #tickler.description# 
  Start Date: #Dateformat(tickler.startdate, 'MM/DD/YY')#
  <hr />
  </cfloop>
  
  Please Advise.
</cfmail>

</cfif>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top