Highlighted

Why my cfloop stop after inserting first id?

Community Beginner ,
Dec 08, 2015

Copy link to clipboard

Copied

I created cfloop that goes through query that I created above the loop. Inside of the loop I have another loop that defines values and then cfquery with insert statement. I tested my loops before I tried to insert my records in database and everything looked good. After I tried to apply that to my cfquery insert, only first ID from cfloop qryRecords is inserted and inserting stops after that. Here is example of my code:

<cfloop query="qryRecords">

     <cfloop condition="TimeStart LTE meetingLength">

          <cfset TimeEnd = dateAdd("n", arguments.meeting, TimeStart)>

          <cfquery name="addRecords" datasource="test">

               Insert Into(Date,Name,Location)

               Values(<cfqueryparam cfsqltype="cf_sql_date" value="#arguments.date#">,

               <cfqueryparam cfsqltype="cf_sql_char" value="#Name#">,

               <cfqueryparam cfsqltype="cf_sql_time" value="#Location#">);

          </cfquery>

          <cfset TimeStart = dateAdd("n", arguments.meeting, TimeStart)>

     </cfloop>

</cfloop>

In my qryRecords I have 40+ records and I should insert multiple time records. My insert do that just for the first record and stop. Like I mentioned above I tried to output that on the screen with this code:

<cfloop query="qryRecords">

     <cfloop from="#test.Stime#" to="#test.Etime#" index="i" step="#CreateTimeSpan(0,0,test.meetingLeng,0)#">

          <cfset TimeEnd = dateAdd("n", test.meetingLeng, i)>

               <tr>

                    <td>(#Id#) - #timeFormat(i, "hh:mm tt")# - #timeFormat(i, "hh:mm tt")#</td>

               </tr>

          <cfset TimeStart = dateAdd("n", test.meetingLeng, i)>

     </cfloop>

</cfloop>

My output after I tested this code looks like this:

(1) - 09:00 AM - 09:15 AM

(1) - 09:15 AM - 09:30 AM

(1) - 09:30 AM - 09:45 AM

(1) - 09:45 AM - 10:00 AM

(1) - 10:00 AM - 10:15 AM

(1) - 10:15 AM - 10:30 AM

(2) - 09:00 AM - 09:15 AM

(2) - 09:15 AM - 09:30 AM

(2) - 09:30 AM - 09:45 AM

(2) - 09:45 AM - 10:00 AM

(2) - 10:00 AM - 10:15 AM

(2) - 10:15 AM - 10:30 AM

(3) - 09:00 AM - 09:15 AM

(3) - 09:15 AM - 09:30 AM

(3) - 09:30 AM - 09:45 AM

(3) - 09:45 AM - 10:00 AM

(3) - 10:00 AM - 10:15 AM

(3) - 10:15 AM - 10:30 AM

.......... so on.

I can't see anything wrong with my Insert query and why that stops after inserting just one sequence of records in db. If anyone can see where I'm making mistake in my code please let me know.

Views

244

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Why my cfloop stop after inserting first id?

Community Beginner ,
Dec 08, 2015

Copy link to clipboard

Copied

I created cfloop that goes through query that I created above the loop. Inside of the loop I have another loop that defines values and then cfquery with insert statement. I tested my loops before I tried to insert my records in database and everything looked good. After I tried to apply that to my cfquery insert, only first ID from cfloop qryRecords is inserted and inserting stops after that. Here is example of my code:

<cfloop query="qryRecords">

     <cfloop condition="TimeStart LTE meetingLength">

          <cfset TimeEnd = dateAdd("n", arguments.meeting, TimeStart)>

          <cfquery name="addRecords" datasource="test">

               Insert Into(Date,Name,Location)

               Values(<cfqueryparam cfsqltype="cf_sql_date" value="#arguments.date#">,

               <cfqueryparam cfsqltype="cf_sql_char" value="#Name#">,

               <cfqueryparam cfsqltype="cf_sql_time" value="#Location#">);

          </cfquery>

          <cfset TimeStart = dateAdd("n", arguments.meeting, TimeStart)>

     </cfloop>

</cfloop>

In my qryRecords I have 40+ records and I should insert multiple time records. My insert do that just for the first record and stop. Like I mentioned above I tried to output that on the screen with this code:

<cfloop query="qryRecords">

     <cfloop from="#test.Stime#" to="#test.Etime#" index="i" step="#CreateTimeSpan(0,0,test.meetingLeng,0)#">

          <cfset TimeEnd = dateAdd("n", test.meetingLeng, i)>

               <tr>

                    <td>(#Id#) - #timeFormat(i, "hh:mm tt")# - #timeFormat(i, "hh:mm tt")#</td>

               </tr>

          <cfset TimeStart = dateAdd("n", test.meetingLeng, i)>

     </cfloop>

</cfloop>

My output after I tested this code looks like this:

(1) - 09:00 AM - 09:15 AM

(1) - 09:15 AM - 09:30 AM

(1) - 09:30 AM - 09:45 AM

(1) - 09:45 AM - 10:00 AM

(1) - 10:00 AM - 10:15 AM

(1) - 10:15 AM - 10:30 AM

(2) - 09:00 AM - 09:15 AM

(2) - 09:15 AM - 09:30 AM

(2) - 09:30 AM - 09:45 AM

(2) - 09:45 AM - 10:00 AM

(2) - 10:00 AM - 10:15 AM

(2) - 10:15 AM - 10:30 AM

(3) - 09:00 AM - 09:15 AM

(3) - 09:15 AM - 09:30 AM

(3) - 09:30 AM - 09:45 AM

(3) - 09:45 AM - 10:00 AM

(3) - 10:00 AM - 10:15 AM

(3) - 10:15 AM - 10:30 AM

.......... so on.

I can't see anything wrong with my Insert query and why that stops after inserting just one sequence of records in db. If anyone can see where I'm making mistake in my code please let me know.

Views

245

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 08, 2015 0
Engaged ,
Dec 08, 2015

Copy link to clipboard

Copied

First not sure what DB you are using, but the syntax for an insert is probably INSERT INTO TABLENAME VALUES ...

Second, what is the initial value of TimeStart and MeetingLength?  My guess is that on the first pass the value is being evaluated to true for whatever reason, and after that it is false and hence the loop will stop.  I'd recommend using cfoutput to write out the value of TimeStart at the end of the loop, or <cfdump var="#TimeStart LTE meetingLength#" /> on the last line inside the cfloop to see if if it evaluates to true or false.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 08, 2015 1
pirlo89 LATEST
Community Beginner ,
Dec 08, 2015

Copy link to clipboard

Copied

I will try to do that and see the output. Thanks for help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 08, 2015 0