Ok thought I would put my 2cents in here. I figured if you wanted to adapt it for more than 3 columns or less than 3 columns it would be silly to be hard coding in cells so here you go. <cfset query = queryNew("") /> <cfset queryAddColumn(query, "column", listToArray("1,2,3,4,5,6,7,8,9,10,11")) /> <cfset columns = 3 /> <cfset rows = CEILING(query.recordCount / columns) />
<cfoutput> <table border="1"> <cfloop from="1" to="#rows#" index="row"> <tr> <cfloop from="0" to="#columns-1#" index="cell"> <td> <cfif row + ((rows * cell)) LTE query.recordCount> #query["column"][row + ((rows * cell))]# <cfelse> </cfif> </td> </cfloop> </tr> </cfloop> </table> </cfoutput> This will also fill any empty cells automatically Have fun Steve Onnis ________________________________ From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Andrew Scott Sent: Thursday, 5 April 2007 6:12 PM To: cfaussie@googlegroups.com Subject: [cfaussie] Re: outputting recordset Yes they are very quick and it wouldn't make any perfomace issue one way or the other. On 4/5/07, Dale Fraser <[EMAIL PROTECTED]> wrote: Ahh, Picky, in my defence, array functions are very quick :P Regards Dale Fraser http://dale.fraser.id.au/blog -----Original Message----- From: cfaussie@googlegroups.com [mailto: cfaussie@googlegroups.com <mailto:cfaussie@googlegroups.com> ] On Behalf Of Scott Thornton Sent: Thursday, 5 April 2007 4:26 PM To: cfaussie@googlegroups.com Subject: [cfaussie] outputting recordset Hi, You probably don't want to calculate the length of the array within every iteration of the loop if it does not change. <cfset arraylength = arrayLen(data)> >>> "Dale Fraser" < [EMAIL PROTECTED]> 05/04/2007 3:29 pm >>> Working example. <cfset data = listToArray('1,2,3,4,5,6,7,8,9,10,11,12,13') /> <cfset cols = 3 /> <cfset rows = ceiling(arrayLen(data) / cols) /> <cfoutput> <table> <cfloop index="i" from="1" to="#rows#"> <tr> <cfif i lte arrayLen(data)><td>#data[i]#</td></cfif> <cfif i+rows*1 lte arrayLen(data)><td>#data[i+rows*1]#</td></cfif> <cfif i+rows*2 lte arrayLen(data)><td>#data[i+rows*2]#</td></cfif> </tr> </cfloop> </table> </cfoutput> Regards Dale Fraser http://dale.fraser.id.au/blog _____ From: cfaussie@googlegroups.com <mailto:cfaussie@googlegroups.com> [mailto:[EMAIL PROTECTED] On Behalf Of Taco Fleur Sent: Thursday, 5 April 2007 3:22 PM To: cfaussie@googlegroups.com <mailto:cfaussie@googlegroups.com> Subject: [cfaussie] Re: outputting recordset Hi Seona, that is it! Thanks. * count * count + divisor * count + (divisor * 2) On 4/5/07, Seona Bellamy < [EMAIL PROTECTED]> wrote: On 05/04/07, Dale Fraser < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED] > > wrote: So are you saying a fixed number of rows 6 Or a fixed number of columns 3? I believe the line in the original email was: I need to output a recordset in a table, infinite rows, and maximum 3 columns in width. I'm more interested in knowing if there was a reason for the number of empty cells in the third column. Because I'm pretty sure that the columns could have been closer to even in length, and that would be easier to do I think. The maths is making better sense in my head, anyway. Then again, knowing my history with maths, I'm not sure that's saying much... Basically, what I'm thinking is something along these lines: * Divide your number of records by 3 and round it off to an integer (I'll call this divisor). This is the number of records you will have in each of the first two (complete) columns. The third column may or may not have this many records. * Loop over your recordset this many times, with a counter of some sort to count the iterations. * In the loop, get the three cells as follows: * count * count + divisor * count + (divisor * 2) I haven't tested this, so it's purely theoretical and may or may not work. Oh, and you'd probably want to test if the value exists in the third column because that one may not be full. Cheers, Seona. Web Design, Web development, Graphic Design and Complete Internet Solutions an industry leader with commercial IT experience since 1994 . www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cfaussie" group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~----------~----~----~----~------~----~------~--~---