Why my cfloop stop after inserting first id?

蓝咒 提交于 2019-12-20 02:58:22

问题


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 insert my records my insert statement terminates after inserting first records from my . 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(TimeStart, "hh:mm tt")# - #timeFormat(TimeEnd, "hh:mm tt")#</td>
                    </tr>
                <cfset TimeStart = dateAdd("n", test.meetingLeng, i)>           
            </cfloop>       
</cfloop>

My output after I tested this code looks like this:

    (3) 08:30 AM - 08:40 AM
    (3) 08:40 AM - 08:50 AM
    (3) 08:50 AM - 09:00 AM
    (3) 09:00 AM - 09:10 AM
    (3) 09:10 AM - 09:20 AM
    (3) 09:20 AM - 09:30 AM
    (3) 09:30 AM - 09:40 AM
   *(12) 09:40 AM - 08:40 AM
    (12) 08:40 AM - 08:50 AM
    (12) 08:50 AM - 09:00 AM
    (12) 09:00 AM - 09:10 AM
    (12) 09:10 AM - 09:20 AM
    (12) 09:20 AM - 09:30 AM
    (12) 09:30 AM - 09:40 AM
   *(23) 09:40 AM - 08:40 AM
    (23) 08:40 AM - 08:50 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.


回答1:


If qryRecords doesn't contain a TimeStart column, then TimeStart needs to be reset between the 2 opening cfloop tags (btwn <cfloop query="qryRecords"> and <cfloop condition="TimeStart LTE meetingLength">). Also, the cfloop condition should be comparing TimeStart w/ the last slot's start time (not the meetingLength minutes).



来源:https://stackoverflow.com/questions/34167974/why-my-cfloop-stop-after-inserting-first-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!