Skip to main content
Inspiring
May 16, 2008
Question

CFLOOP Help

  • May 16, 2008
  • 3 replies
  • 462 views
I have a simple loop

<cfloop list="#prodDetails.matchProds#" index="matching" delimiters=",">
<cfoutput>
<a href="/catalog/?ProductID=#matching#&Category=#URL.category#"> #matching#</a><br />
</cfoutput>
</cfloop>

That currents displays results as:

Value 1
Value 2
Value 3
etc...

I am trying to figure out how to make the out appear as such:

Value 1 Value 2
Value 3 Value 4
Value 5 etc...

Any help here would be much appreciated. Regards.
This topic has been closed for replies.

3 replies

Inspiring
May 16, 2008
To make that code more efficient, put the loop inside the cfoutput instead of the way you have it now.
bfinelsenAuthor
Inspiring
May 16, 2008
Thank you! Using your suggestion, I have used a boolean type of syntax to make it work perfectly. Many thanks.
Inspiring
May 16, 2008
bfinelsen wrote:
>
> Value 1 Value 2
> Value 3 Value 4
> Value 5 etc...
>
> Any help here would be much appreciated. Regards.
>

You need a conditional <cfif> block around the <br/> tag.

The condition for this if block needs to be true when you want the <br/>
displayed and when it is not.

If you want to and only two elements between each <br/> tag, you could
get by with a boolean that is flipped back and forth.

If you want more flexibility where you can have different numbers of
element between the <br/> tags, use a counter and the MOD operator.

Is that enough help?

Participating Frequently
May 16, 2008
Something like this?

<cfloop list="#prodDetails.matchProds#" index="matching" delimiters=",">
<cfoutput>
<cfif matching MOD 2 EQ 0>
<a href="/catalog/?ProductID=#matching#&Category=#URL.category#"> #matching#</a><br />
<cfelse>
<a href="/catalog/?ProductID=#matching#&Category=#URL.category#"> #matching#</a>&nbsp
</cfif>
</cfoutput>
</cfloop>

Phil