为什么我的cfloop在插入第一个ID后停止? [英] Why my cfloop stop after inserting first id?

查看:106
本文介绍了为什么我的cfloop在插入第一个ID后停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了cfloop,它通过我在循环之上创建的查询。在循环内部我有另一个循环定义值,然后cfquery与insert语句。我测试我的循环,然后我试图插入我的记录在数据库,一切看起来不错。在我尝试应用它插入我的记录后,我的插入语句在从我的插入第一个记录后终止。这里是我的代码的例子:

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>

在我的qryRecords我有40多个记录,我应该插入多个时间记录。我的插入做这只是为第一个记录和停止。就像我上面提到的那样,我试图用下面的代码在屏幕上输出:

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.

我看不到任何错误的插入查询和为什么停止插入只有一个序列记录在db。如果任何人可以看到我在我的代码错误,请让我知道。

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.

推荐答案

如果qryRecords不包含TimeStart列,则TimeStart需要在2个打开的cfloop标记之间重置(btwn < cfloop query =qryRecords> < cfloop condition =TimeStart LTE meetingLength> )。此外,cfloop条件应该将TimeStart与上次插槽的开始时间(而不是meetingLength分钟)进行比较。

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).

这篇关于为什么我的cfloop在插入第一个ID后停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆