English 中文(简体)
冷漠视纪录
原标题:ColdFusion Conditional RecordCount
  • 时间:2011-09-26 21:21:09
  •  标签:
  • coldfusion

Alright SOuser... 这里似乎不可能作出错误的有条件陈述。 然而,我无法指出,为什么它赢得预期工作。

<cfoutput query="checkForAd">
        <!--- also used the line <cfif RecordCount eq 0> --->
    <cfif checkForAd.RecordCount eq 0>
        <!--- Display some message. (Perhaps using a table, undecided) --->
    <cfelse>
        <!--- Display some other message. (Happens to be a table) --->
    </cfif>
</cfoutput>

当纪录乐团返回人数超过0时,其他案件显示得当。 记录Cunt返回时,没有显示任何情况,而且表格继续沿途。 我感到非常沮丧,因为这应当非常简单。

最佳回答

The output won t return any results if the query set is empty. Try:

<cfif checkForAd.RecordCount eq 0>
    <!--- Display some message. (Perhaps using a table, undecided) --->
<cfelse>
    <cfoutput query="checkForAd">
        <!--- Display some other message. (Happens to be a table) --->
    </cfoutput>
</cfif>

I assume that you re looking to return a number of records... if you were just returning one, the query="checkForAd" isn t necessary. You can simply reference the query & variables in a <cfoutput></cfoutput>.

<><>Edit>/strong>

查阅查询变量的途径之一:QueryName[“ColumnName”][RowNum]

(在你希望扩大编码时,你可以做许多与点变量有关的工作。) https://stackoverflow.com/questions/429219/coldfusion-and-access-data- from-mysql” 冷藏和从MySQL获取数据

问题回答

如nykash所指出的,如果没有任何记录,那么<代码>cfoutput query(或cfloop query)的仪器就永远不会执行,因此,核对零记录永远不会在其中。

然而,我发现以下一个可读的例子:

<cfif NOT checkForAd.RecordCount >
    <!--- Display some message. --->
</cfif>

<cfoutput query="checkForAd">
        <!--- loop through data --->
</cfoutput>

这似乎并不完全孤立,但我认为,看到正在发生什么,特别是在与其他法典合并时,会比较清洁和容易。

Specifically on the RecordCount check, if I care about the specific number then I ll use EQ (or NEQ/GT/etc) but if I only care about "having records" vs "not having records" then I use the implicit boolean conversion that CFML provides to simplify the code. This really makes it easier to identify when I m using the common binary choice or a more significant one, so navigating through the code is easier.





相关问题
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, ...

热门标签