ColdFusion:你可以使用recordCount从查询中提取一个唯一的记录吗? [英] ColdFusion: Can you pull out a unique record from a query using recordCount?

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

问题描述

这是一个棘手的问题,但是,我的页面,大多数额定乐队显示乐队的标志,按照他们被评为多高的顺序。我唯一的问题是,我想通过使用cfloop从1到10计数,因为它分为两列,有一个计数从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.

有人可以帮我吗?

    <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%" />


因为您嵌套/ $ cfloop < cfoutput query => 块中,您会得到意想不到的结果。您现有的代码总是要求您的外部循环提供的记录。因此,你看到相同的图像5次。 (使用任何提供的精细示例将帮助您摆脱这一点),但是您可以从 cfoutput 中删除​​查询,只需要求CF显示


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天全站免登陆