?
Solved

Coldfusion Horizontal-"loop" part2

Posted on 2009-12-16
16
Medium Priority
?
324 Views
Last Modified: 2013-12-24
Hello experts.
On this page:http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Cold_Fusion_Markup_Language/Q_24970609.html  i have a solution to build a coldfusion horizontal loop.
The solution is :
<cfset multiple = 4>
<cfset counter = 0>
<cfoutput query="queryartikel" startRow="#StartRow_queryartikel#" maxRows="#MaxRows_queryartikel#">
  <cfset counter = counter+1>
  <td>#items.name#</td>
  <cfif counter MOD multiple EQ 0></tr><tr></cfif>
</cfoutput>
The problem i have now is that when the outputs f.e are 6 i have in the first row 4 td and in the second 2 td.
In ff i have not problems in design but in other browsers it seems to cause problems.
Any help?
0
Comment
Question by:Panos
  • 9
  • 7
16 Comments
 
LVL 27

Expert Comment

by:azadisaryev
ID: 26061384
something like this:

<cfset counter = 0>
<table>
<tr>
<cfoutput query="queryartikel" startRow="#StartRow_queryartikel#" maxRows="#MaxRows_queryartikel#">
  <cfset counter = counter+1>
  <td>#items.name#</td>
  <cfif counter MOD multiple EQ 0 AND counter LT MaxRows_queryartikel></tr><tr></cfif>
</cfoutput>
<cfoutput>#repeatstring('<td></td>', MaxRows_queryartikel - counter)#</cfoutput>
</tr>
</table>

mind you, that is off the top of my head - not tested...

Azadi
0
 
LVL 2

Author Comment

by:Panos
ID: 26061477
It is not working.
The counter will have the same value with Maxrows or not?
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 26061708
>> The counter will have the same value with Maxrows or not?

right you are! silly me...
try changing
<cfoutput>#repeatstring('<td></td>', MaxRows_queryartikel - counter)#</cfoutput>
to this:
<cfif MaxRows_queryartikel MOD multiple NEQ 0><cfoutput>#repeatstring('<td>&nbsp;</td>', round(multiple-MaxRows_queryartikel/multiple))#</cfoutput></cfif>

Azadi
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:Panos
ID: 26062068
First i have to check if multiple GT MaxRows_queryartikel.
<cfif (MaxRows_queryartikel - multiple) LT 0 >
 <cfoutput>#repeatstring('<td>&nbsp;</td>', multiple- MaxRows_queryartikel)#</cfoutput>
<cfelseif MaxRows_queryartikel MOD multiple NEQ 0 AND (MaxRows_queryartikel - multiple) GT 1>
(may be i have syntax error please azadi check this)
This is not working azadi.
If fe Maxrows is 7 i will have round(4-7/4).This will be 2,25 -rounded 2 instead of 1 i need.  
for  Maxrows 13    round(4-13/4).This willbe 0,75 -1 it willwork.
for  Maxrows 21    round(4-21/4).This wiil be -1,25 (is it working for ngative values?)
0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 2000 total points
ID: 26062447
sorry, i will blame my cold for this...

i have severely over-engineering things. all you need is this:
<cfif MaxRows_queryartikel GT multiple AND NOT MaxRows_queryartikel MOD multiple><cfoutput>#repeatstring('<td>&nbsp;</td>',multiple-(MaxRows_queryartikel MOD multiple))#</cfoutput></cfif>

Azadi
0
 
LVL 2

Author Comment

by:Panos
ID: 26062936
You are using azadi the Maxrows value.Why?
MaxRows in my page can be set to 8  16 and 40.
All these with MOD multiple have result 0.and for multiple-(MaxRows_queryartikel MOD multiple) i have always result 4.
Is the  recordcount value not more usefull to handle this?
0
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 2000 total points
ID: 26063042
>> You are using azadi the Maxrows value.Why?
because from your code it looks like you are outputting just a subset of query results, like paginated resultset of something like that.

>> All these with MOD multiple have result 0.and for multiple-(MaxRows_queryartikel MOD multiple) i have
>> always result 4.
sorry, bad copy/paste.
the correct cfif statement should be:
<cfif MaxRows_queryartikel GT multiple AND MaxRows_queryartikel MOD multiple NEQ 0>

>> Is the  recordcount value not more usefull to handle this?
it may be, or it may be not - depends on your code.

Azadi
0
 
LVL 2

Author Comment

by:Panos
ID: 26063045
Well azadi
the following code  is working but i need correction in the cfif tags because even if i have 4 output i still get 4 extra td in a new row.
<cfif counter MOD multiple EQ 0 AND counter LT MaxRows_queryartikel>
</tr><tr>
</cfif>
</cfoutput>
<cfif MaxRows_queryartikel GT multiple AND NOT MaxRows_queryartikel MOD multiple>
<cfoutput>#repeatstring('<td>&nbsp;</td>',multiple-(counter MOD multiple))#
</cfoutput></cfif>
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 26063060
see my post above your last one.

Azadi
0
 
LVL 2

Author Comment

by:Panos
ID: 26063128
This is the final working code for me azadi:
<cfif counter MOD multiple EQ 0 AND counter LT MaxRows_queryartikel>
</tr><tr>
</cfif>
</cfoutput>
<cfif MaxRows_queryartikel GT multiple AND counter MOD multiple NEQ 0>

<cfoutput>#repeatstring('<td>&nbsp;</td>',multiple-(counter MOD multiple))#
</cfoutput></cfif>
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 26063304
that's exactly the same as my code, considering your counter will always equal MaxRows_queryartikel.

Azadi
0
 
LVL 2

Author Comment

by:Panos
ID: 26063325
I did not see your last post azadi but i did test it now and it is not working like the code below.
The result of multiple-(MaxRows_queryartikel MOD multiple) is still 4.I explained the reason.
Sorry
a little correction
<cfif counter MOD multiple EQ 0>
</tr><tr>
</cfif>
</cfoutput>
<cfif MaxRows_WADAdboartikel GT multiple AND counter MOD multiple NEQ 0>

<cfoutput>#repeatstring('<td>&nbsp;</td>',multiple-(counter MOD multiple))#
</cfoutput></cfif>
</tr>
</table>
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 26063352
well, ok, you know better what your variables evaluate to. if the counter var works then obviously use that one.
it was not really possible to tell from your code exactly which var should be used...

Azadi
0
 
LVL 2

Author Comment

by:Panos
ID: 26063442
I still cannot see where the problem is.
i made 3 outputs to check the values of:#Maxrows_queryartikel#  #multiple-(counter MOD multiple)# and #counter#

(<cfif MaxRows_queryartikel GT multiple AND counter MOD multiple NEQ 0>

<cfoutput>#repeatstring('<td>&nbsp;</td>',multiple-(counter MOD multiple))# &nbsp;&nbsp;#MaxRows_queryartikel# #multiple-(counter MOD multiple)# #counter#
</cfoutput></cfif> )

For 13 outputs and maxrows 8 i have in my second page the values

8  3  5    
That means that in the second page i have two rows.The first one has 4 (multiple=4),the second 1, and 3 '< td></td>'.(that what we are looking for.
0
 
LVL 2

Author Comment

by:Panos
ID: 26063449
I miised your post azadi.
Thank you!
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 31666695
Thank you again azadi.
regards
panos
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question