Using this method you might want to look at the source that's produced as it
won't be a clean table.
You will have an extra <tr> at the end for multiples of 5 and for any other
values you will need an extra </tr>
Run this as a test page:
<cfoutput>
<table border="1">
<tr>
<cfloop from="1" to="20" index="i">
<td>#i#</td>
<cfif i MOD 5 EQ 0>
</tr><tr>
</cfif>
</cfloop>
</table>
</cfoutput>
View the source for 20 and 22 items. View the source in both cases.
Save the following as a test page and play about with the potential record
count. There may be a cleaner way but this seems to work with all the
boundary numbers I've used:
<cfoutput>
<cfset to = 20>
<cfsavecontent variable="output"><table border="1">
<tr>
<cfloop from="1" to="#to#" index="i">
<td>#i#</td>
<cfif i MOD 5 EQ 0>
</tr>
<!--- This will stop the extra <tr> after the last row
--->
<cfif i NEQ to>
<tr>
</cfif>
<!--- Add a </tr> to the last row when the results are not a
multiple of
5 --->
<cfelseif i EQ to AND i MOD 5>
<!--- For when you want a completed row --->
#RepeatString("<td> </td>", 5 - i MOD 5)#
</tr>
</cfif>
</cfloop>
</table></cfsavecontent>
#output#
<textarea cols="100" rows="40">#output#</textarea>
</cfoutput>
Adrian
-----Original Message-----
From: Richard Groen
Sent: 06 September 2007 08:46
To: CF-Newbie
Subject: RE: create dynamic table with max columns
Thanks all.
See the below solution for it which worked for me. Thanks again.
====
<cfquery name="get_projects" datasource="dsn_meike">
Select projecttitel
from tbl_projecten
</cfquery>
<table border="1">
<tr>
<cfoutput query="get_projects">
<td valign="top">#projecttitel#</td>
<cfif CurrentRow MOD 5 EQ 0>
</tr><tr>
</cfif>
</cfoutput>
</table>
======
-----Original Message-----
From: Weidler, Wilfred C.
Sent: Wednesday, September 05, 2007 9:11 PM
To: CF-Newbie
Subject: RE: create dynamic table with max columns
Here is another example of how to do it. It might help.
<cfquery name="parks" datasource="cfdocexamples">
select top 7 parkName, parkType, city, state
from parks
order by parkName
</cfquery>
<table border="1">
<tr>
<cfoutput query="parks">
<td valign="top">#parkName#<br>#parkType#<br>#city#,
#state#</td>
<cfif CurrentRow MOD 5 EQ 0>
</tr><tr>
</cfif>
</cfoutput>
</table>
Chuck
-----Original Message-----
From: richard groen
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get involved in the latest ColdFusion discussions, product
development sharing, and articles on the Adobe Labs wiki.
http://labs/adobe.com/wiki/index.php/ColdFusion_8
Archive:
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:3046
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15