0

I am trying to display 2 images, and skip one if it matches the following criteria (<cfif myDir.name eq property_mainimage> which works fine, and then continue onto the next image and display the next image until I have a total of 2 images. But when the criteria image is say in row 5, the loop displays 3 images, when the criteria image is say row 1, it displays 2 images.

There doesn't seem to be a skip row in cfloop?

I have tried <cfif counter gt 3 > <cfabort> which works but it displays the 3 images still of the criteria image is in a row greater than 3. Below is what i'm working with...

<cfdirectory directory="C:\Domains\domain.com\wwwroot\uploads\images\#property_ID#\" filter="*.jpg" name="myDir" type="file" sort="datelastmodified">
<ul>
  <cfset counter = 0>
  <cfset endrowvalue = 3 >
  <cfloop query="myDir" endRow="#endrowvalue#">
    <cfset counter = counter +1 >
    <li>
    <cfif right(myDir.name,4) is ".jpg">
      <cfif fileexists("C:\Domains\ domain.com\wwwroot\uploads\ images\#property_ID#\#left(mydir.name,len(myDir.name)-4)#.jpg")>
        <cfif myDir.name eq property_mainimage>
          DO NOT SHOW THIS IMAGE
        <cfelse>
          <cfset endrowvalue = 1 >
          <cfset myDir.endRow = 1 >
          test #endrowvalue#
          test #counter# <img src="#request.root#uploads/images/#property_ID#/#myDir.name#" border="0" width="230px" style="margin-bottom:15px;"  />
        </cfif>
      </cfif>
    </cfif> 
    </li>
  </cfloop>
</ul>

any help would be most appreciated.

4

2 回答 2

2

当您显示图像时,我会使用计数器进行计数。一旦您显示 2 张图像,就会跳出循环。

<cfdirectory directory="C:\Domains\domain.com\wwwroot\uploads\images\#property_ID#\" filter="*.jpg" name="myDir" type="file" sort="datelastmodified">
<ul>
  <cfset counter = 1>
  <cfloop query="myDir">
    <li>
      <cfif right(myDir.name,4) is ".jpg">
        <cfif fileexists("C:\Domains\ domain.com\wwwroot\uploads\ images\#property_ID#\#left(mydir.name,len(myDir.name)-4)#.jpg")>
          <cfif myDir.name eq property_mainimage>
            DO NOT SHOW THIS IMAGE
          <cfelse>
            <!--- image displayed increment coutner --->
            <cfset counter++>
            <img src="#request.root#uploads/images/#property_ID#/#myDir.name#" border="0" width="230px" style="margin-bottom:15px;"  />
          </cfif>
        </cfif>
      </cfif> 
      <cfif counter EQ 2>
        <cfbreak>
      </cfif>
    </li> 
  </cfloop>
</ul>
于 2015-09-25T13:05:00.760 回答
0

这是一个格式化的评论。你的代码有这个:

<cfset endrowvalue = 3 >
<cfloop query="myDir" endRow="#endrowvalue#">
    <cfif myDir.name eq property_mainimage>
      DO NOT SHOW THIS IMAGE
    <cfelse>
      <cfset endrowvalue = 1 >

您必须对其进行测试才能确定,但​​我怀疑您的 cfloop 标记的 endRow 属性将继续为 3,即使您将 endrowvalue 变量的值更改为 1。

这可能不是您当前问题的原因,但是,如果我的怀疑者是正确的,您将在其他地方遇到问题,或者您正在运行一个毫无意义的命令。

于 2015-09-25T13:40:18.513 回答