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

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

问题描述

我创建了 cfloop,它通过我在循环上方创建的查询.在循环内部,我有另一个定义值的循环,然后是带有 insert 语句的 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.

我看不出我的插入查询有什么问题,以及为什么在数据库中只插入一个记录序列后它就停止了.如果有人能看到我在代码中出错的地方,请告诉我.

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

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

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