0
CFLOOP Help
Explorer
,
/t5/coldfusion-discussions/cfloop-help/td-p/956005
May 16, 2008
May 16, 2008
Copy link to clipboard
Copied
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.
<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.
TOPICS
Advanced techniques
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/cfloop-help/m-p/956006#M87338
May 16, 2008
May 16, 2008
Copy link to clipboard
Copied
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?
>
> 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?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Mentor
,
/t5/coldfusion-discussions/cfloop-help/m-p/956007#M87339
May 16, 2008
May 16, 2008
Copy link to clipboard
Copied
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> 
</cfif>
</cfoutput>
</cfloop>
Phil
<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> 
</cfif>
</cfoutput>
</cfloop>
Phil
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/cfloop-help/m-p/956009#M87341
May 16, 2008
May 16, 2008
Copy link to clipboard
Copied
paross1 wrote:
> 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> 
> </cfif>
> </cfoutput>
> </cfloop>
>
> Phil
>
Somewhat, except that I would just put the <cfif> block around the <br/>
tag, not the entire <a...> tag that is the same in both clauses.
But <cfif matching MOD 2> does not work in this case. Since this is a
list loop 'matching' is going to be a string containing each element in
the list.
One would need to either create an independent counter to be used in the
MOD clause or use a listFind() function to get the numeric position from
the list from which the string in 'matching' came.
> 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> 
> </cfif>
> </cfoutput>
> </cfloop>
>
> Phil
>
Somewhat, except that I would just put the <cfif> block around the <br/>
tag, not the entire <a...> tag that is the same in both clauses.
But <cfif matching MOD 2> does not work in this case. Since this is a
list loop 'matching' is going to be a string containing each element in
the list.
One would need to either create an independent counter to be used in the
MOD clause or use a listFind() function to get the numeric position from
the list from which the string in 'matching' came.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
bfinelsen
AUTHOR
Explorer
,
/t5/coldfusion-discussions/cfloop-help/m-p/956008#M87340
May 16, 2008
May 16, 2008
Copy link to clipboard
Copied
Thank you! Using your suggestion, I have used a boolean type
of syntax to make it work perfectly. Many thanks.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/cfloop-help/m-p/956010#M87342
May 16, 2008
May 16, 2008
Copy link to clipboard
Copied
To make that code more efficient, put the loop inside the
cfoutput instead of the way you have it now.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

