ColdFusion:您能否使用 recordCount 从查询中提取唯一记录? [英] ColdFusion: Can you pull out a unique record from a query using recordCount?

查看:19
本文介绍了ColdFusion:您能否使用 recordCount 从查询中提取唯一记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个有点棘手的问题,但是,我的大多数评分乐队的页面会按照评分的高低顺序显示乐队徽标.我唯一的问题是我想通过使用从 1 到 10 的 cfloop 来计算记录,因为它被分成两列,一个从 1 到 9,另一个从 2 到 10,每个都有步骤两个.

It's a bit of tricky question, however, my page for most rated bands displays the band logos in order of how high they have been rated. My only problem is i want to count through the records by using a cfloop from 1 to 10 and because it is split in to two columns, have one counting 1 through to 9 and the other 2 through to 10, each of them with steps of two.

谁能帮我解决这个问题?如果我感到困惑,只需提及它,我会尝试澄清我的意思.

Can anybody help me with this? If i've confused just mention it and ill try to clarify exactly what i mean.

    <DIV class="community_middle">

    <cfoutput query="top10MostRated">
        <cfloop from="2" to="10" index="i" step="2">
        <DIV class="communityContent">
                            #chr(i)#
            <IMG src="logo/#top10MostRated.Logo#" alt="#top10MostRated.Name#" width="100%" height="100%"></IMG>
        </DIV>
        <BR/>
        </cfloop>
    </cfoutput>

</DIV>

推荐答案

我认为这些答案解决了您问题的并排部分,但没有解释相同图像"问题.他们的代码写得对,但没有解释原因.

I think these answers address your side-by-side part of your question but does not explain the "same image" issue. Their code is written correctly but does not explain the reason.

您的代码:

        <IMG src="logo/#top10MostRated.Logo#" 
             alt="#top10MostRated.Name#" 
             width="100%" height="100%"></IMG>


... 如果您只在 <cfloop query = "top10MostRated"><cfoutput query = "top10MostRated"> 块内,那就没问题了.原因是因为在这些类型的块中,CF 足够聪明,可以知道您想要当前行的数据.这将与以下内容相同:


... would be fine if you were only inside a <cfloop query = "top10MostRated"> or <cfoutput query = "top10MostRated"> block. The reason is because inside these types of blocks CF is smart enough to know you want the data for the current row. It would be the same as:

        <IMG src="logo/#top10MostRated.Logo[top10MostRated.currentRow]#" 
             alt="#top10MostRated.Name[top10MostRated.currentRow]#" 
             width="100%" height="100%" />


因为您将 to/from cfloop 嵌套在 <cfoutput query = ""> 块中,所以您会得到意想不到的结果.您现有的代码总是要求您的外部循环提供的记录.因此,您会看到相同的图像 5 次.(使用提供的任何优秀示例将帮助您摆脱这种情况)但是,您可以从 cfoutput 中删除查询,并简单地要求 CF 向您显示循环中正确行的值,使用您的索引(您将索引设置为i"),因此下面会显示与您的循环相对应的图像.


Because you're nesting the to/from cfloop inside a <cfoutput query = ""> block, you are getting unexpected results. Your existing code is always asking for the record provided by your outer loop. Hence you see the same image 5 times. (using any of the fine examples provided will help you get out of this) but, you can remove the query from your cfoutput and simply ask CF to show you the value for the correct row in your loop using your index (you set your index to "i") so the below would show you the image that corresponds to your loop.

        <IMG src="logo/#top10MostRated.Logo[i]#" 
              alt="#top10MostRated.Name[i]#" 
              width="100%" height="100%" />

这篇关于ColdFusion:您能否使用 recordCount 从查询中提取唯一记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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