2 Replies Latest reply on Dec 8, 2015 7:10 PM by pirlo89

    Why my cfloop stop after inserting first id?

    pirlo89

      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.