English 中文(简体)
CF 失踪人员调查委员会
原标题:CFLoop Error For Missing Entries

please disregard this post. I have made a clearer example of my problem here: Error with CFLoop When Entries Are Missing

下面是CFLoop编码。

<cfset data = queryNew("sid,firstname,lastname,age","integer,varchar,varchar,integer")>
<cfloop index="x" from="1" to="50">
    <cfset queryAddRow(data)>
    <cfset querySetCell(data,"sid",x)>
    <cfset querySetCell(data,"firstname","#first[x]#")>
    <cfset querySetCell(data,"lastname","#last[x]#")>
    <cfset querySetCell(data,"age","#studentage[x]#")>
</cfloop>

<cfoutput query="data">
    #sid# -  #firstnamet# #lastname# - #age#<br />
</cfoutput>

正在从外部数据来源中提取<代码>X>。 注:CFLoop有50个条目。

当有数据时,该守则便能很好地发挥作用。 然而,如果缺乏数据,则代码便会中断。 也就是说,如果第11号条目中有一个名字列在<代码>第1[x]上,那么我就按照<代码>的行文出现错误,首先没有界定。 错误出现在第5行上。

(line 5 is the entry for first name).

当出现这种情况时,我要从我的结果中删除第11条(以及造成错误的所有其他条目),防止出现错误。 我如何能够这样做?

Clarification: Please assume the data is defined. It gets a bit hairy since I am using an external datasource. But what I am saying is that Entries 1 to 10 show up. When its entry 11 s turn, that s when the error comes up.

问题回答

利用外部数据库的记录,防止错误。

<cfloop index="x" from="1" to="#ExternalDatabaseQuery.RecordCount#">

A better solution, assuming you do have the query in memory, would be to use a query of queries.

<cfquery dbtype= query  name= data >
SELECT SID, First AS FirstName, Last AS LastName, Age AS StudentAge
FROM ExternalDatabaseQuery
</cfquery>

迈克表示歉意,如果我对你之后的误解表示怀疑,但某些基本条件似乎可以做。 下面对你的法典的编辑只是关于如何做到这一点的建议(当然,完全的法典基础可能带来一些略有不同)。

<cfset data = queryNew("sid,firstname,lastname,age","integer,varchar,varchar,integer")>
<cfloop index="x" from="1" to="50">
    <cfif isDefined("first[x]") AND isDefined("last[x]") AND isDefined("studentage[x]")>
    <cfset queryAddRow(data)>
    <cfset querySetCell(data,"sid",x)>
    <cfset querySetCell(data,"firstname","#first[x]#")>
    <cfset querySetCell(data,"lastname","#last[x]#")>
    <cfset querySetCell(data,"age","#studentage[x]#")>
    </cfif>
</cfloop>

<cfoutput query="data">
    #sid# -  #firstnamet# #lastname# - #age#<br />
</cfoutput>

这里的主要问题(也许这不是你的问题)是,这将产生50个错误。 因此,如果存在3个错误(即没有数据)的话,你就有47个条目产出,而不是50个。 如果是这样的话,请补充一点意见......有一些替代办法可以确保你总有50个项目产出。





相关问题
JQuery AJAX .load - flash chart doesnt load in IE

An IE issue has me completely stumped. I have a coldfusion page that uses JQuery s AJAX .load function to load in a new flash file that is generated by coldFusion s cfchart tag. This works completely ...

Best Coldfusion Library for OpenID [closed]

I am getting ready to start a project that requires using OpenID within Coldfusion 8. I have found a number of different options and was wondering what has worked the best, get s the most support, ...

Find ColdFusion Generated ID

Is there a way to find the elements generated by ColdFusion s <CFLayout> and <CFLayoutArea> tags? These tags: <cflayout type="tab" name="MyAccount"> <cflayoutarea name="...

ColdFusion COM error

I am upgrading from CF4.5 to CF8. Calls to COM dll s that used to work in version 4.5 now throw a "Complex object types cannot be converted to simple values.." error. The COM object has a few arrays ...

What s the best way to write engine-specific CFML code?

Sometimes it is necessary to write different code for Adobe ColdFusion vs Railo vs OpenBD, due to differences in implementation. Do people have a specific method that they use for this? For example, ...

热门标签