Here is a bit more complicated way, but the underlying html is cleaner.

In this example you are treating your recordset as though it was a
structure.

The first loop will give you your rows and the nested loop will give you
your cells.

To change the number of columns in the table you will modify the
variable NumberOfColumns.

<cfquery name="parks" datasource="cfdocexamples">
        select          top 7 parkName, parkType, city, state
        from            parks
        order by        parkName
</cfquery>

<cfset NumberOfColumns = 5>
<cfset idx2Counter = 1>

<cfset addTo = parks.RecordCount MOD NumberOfColumns>
<!--- If you have a remainder you need to add 1 more row. --->
<cfif addTo GT 0>
        <cfset addTo = 1>
</cfif>
<table border="1">
        <cfloop from="1" to="#(parks.RecordCount/NumberOfColumns) +
addTo#" index="idx">
                <tr>
                        <cfloop from="1" to="#NumberOfColumns#"
index="idx2">
                                <td valign="top">
                                        <cfoutput>
                                                <cfif
Len(parks.parkName[idx2Counter])>
        
#parks.parkName[idx2Counter]#<br>
        
#parks.parkType[idx2Counter]#<br>
        
#parks.city[idx2Counter]#, #parks.state[idx2Counter]#
                                                <cfelse>
                                                        &nbsp;
                                                </cfif>
                                        </cfoutput>
                                </td>
                                <cfset idx2Counter = idx2Counter + 1>
                        </cfloop>
                </tr>
        </cfloop>
</table>

Chuck Weidler
Lockheed Martin Information Technology

-----Original Message-----
From: richard groen [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 05, 2007 2:57 PM
To: CF-Newbie
Subject: create dynamic table with max columns

Hi all,

I got one brainteaser (well...for me).

I have a database with, lets say 100 images, these images are 'dynamic'
e.g. it can be 100 but also 151 images. 

My question is:
How can i make a dynamic table where I can set that the maximum columns
to 5. So when parsing the images (generating the query output), then the
function fills up a one row with 5 images (all in a different column)
and the 6th image is at a new row etc. etc.

I just cant figure it out.
Hope you can help! thanks in advance.

Grt,
Richard 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Enterprise web applications, build robust, secure 
scalable apps today - Try it now ColdFusion Today
ColdFusion 8 beta - Build next generation apps

Archive: 
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:3033
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15

Reply via email to