ColdFusion条件RecordCount [英] ColdFusion Conditional RecordCount

查看:190
本文介绍了ColdFusion条件RecordCount的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的SO用户...这是一个看似不可能出错的条件语句。这很简单,但是,我不知道为什么它不会按照预期的方式工作。

 < cfoutput query =checkForAd> 
<!---也使用< cfif RecordCount eq 0>行。 --->
< cfif checkForAd.RecordCount eq 0>
<!---显示一些消息。 (也许使用表,未决)--->
< cfelse>
<!---显示其他消息。 (发生成为表)--->
< / cfif>
< / cfoutput>

当RecordCount返回大于0的数字时,else case会正确显示。当RecordCount返回0时,不显示任何内容,表单沿其路径继续。我已经变得非常沮丧,因为这应该很简单...

解决方案

输出将不会返回任何结果,如果查询集为空。尝试:

 < cfif checkForAd.RecordCount eq 0> 
<!---显示一些消息。 (也许使用表,未决)--->
< cfelse>
< cfoutput query =checkForAd>
<!---显示其他消息。 (发生成为表)--->
< / cfoutput>
< / cfif>

我假设你要返回一些记录...如果你刚刚返回一, query =checkForAd不是必需的。您可以简单地引用查询&

/ p>

以下是访问查询变量的一种方法: QueryName [ColumnName] [RowNum]



(为了扩展你的代码,你可以用查询变量做很多事情。 ColdFusion并从MySQL获取数据


Alright SO users... Here's a seemingly impossible to go wrong conditional statement. It is very simple, however, I cannot figure out why it won't work the way it is expected to.

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

When the RecordCount returns a number greater than 0, the else case displays properly. When RecordCount returns 0, nothing is displayed and the form continues along its path. I've become very frustrated as this should be quite simple...

解决方案

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

Here's one way to access a query variable: QueryName["ColumnName"][RowNum]

(As you look to expand your coding, there's a lot you can do with query variables. There's a great rundown of the different approaches at ColdFusion and getting data from MySQL)

这篇关于ColdFusion条件RecordCount的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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