Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating tables

Status
Not open for further replies.

mkiv

MIS
Jan 6, 2003
14
US
I need to populate 31 cells in a table that would run from the first cell down. After filling 11 cells I would like for the 12th record to run to the next column and after filling another 11 records I would like the 23rd record to jump to the next column. Any suggestions appreciated.

Rye

 
there are two strategies

the first is real easy, involves using only RecordCount, dividing it by however many columns you want (in your case, three), and nesting a table inside each of three cells in a one-row outer table

holler if that didn't make sense

the second strategy uses only one table, and is a little more complex

see dotjeff's post, near the bottom of this thread --

rudy
 
r937,

I have this same issue. I'm checking out dotjeff's post, but can you explain your solution a little better? I'm a bit of a newbie at ColdFusion, although I understand the first portion of your message "...only RecordCount, dividing it by however many columns you want (in your case, three)..." The part that I don't understand is: "...nesting a table inside each of three cells in a one-row outer table..."

Thanks alot for your reply.
 
number of columns is a parameter set in the first line --

[tt]<CFSET cols=3>
<table border=&quot;1&quot; cellpadding=&quot;2&quot;>
<tr><td valign=&quot;top&quot;><table border=&quot;1&quot;>
<CFSET i=0>
<CFOUTPUT QUERY=&quot;yourquery&quot;>
<tr><td>#yourquery.CurrentRow# #yourquery.somefield#</td></tr>
<CFSET i=i+1>
<CFIF i GT yourquery.RecordCount / cols
AND yourquery.CurrentRow LT yourquery.RecordCount>
<CFSET i=0>
</table></td><td valign=&quot;top&quot;><table border=&quot;1&quot;>
</CFIF>
</CFOUTPUT>
</table>
</td></tr></table>[/tt]

print CurrentRow inside the cell just so that you can see the numbering

rudy
 

Something like:

Code:
<CFSET myList = &quot;1,2,3,4,5,6,7,8,9,10,11,12,13,14,15&quot;>

<CFSET columnMax = ListLen(&quot;#myList#&quot;) / 3>

<CFSET myCurrentRow = 0>

<table border=&quot;1&quot; cellpadding=&quot;5&quot;>
<tr>
<CFLOOP index=&quot;whichValue&quot; list=&quot;#myList#&quot;>
<CFIF myCurrentRow LT 1>
<td>
<table border=&quot;1&quot; cellpadding=&quot;5&quot;>

</CFIF>

<CFOUTPUT><tr><td>#whichValue#</td></tr></CFOUTPUT>


<CFSET myCurrentRow = myCurrentRow + 1>

<CFIF myCurrentRow GTE columnMax>
</table>
</td>
<CFSET myCurrentRow = 0>

</CFIF>

</CFLOOP>
</tr>
</table>

If you copy the above to a CFM page, you'll be able to see the nested table structure Rudy's talking about.

To alter the code to use the values from your query, you'd simply do something like:

Code:
<cfquery name=&quot;myQuery&quot; ...>
	SELECT *
	  FROM ...
</cfquery>


<CFSET columnMax = myQuery.RecordCount / 3>

<CFSET myCurrentRow = 0>

<table border=&quot;1&quot; cellpadding=&quot;5&quot;>
<tr>
<CFOUTPUT query=&quot;myQuery&quot;>
<CFIF myCurrentRow LT 1>
<td>
<table border=&quot;1&quot; cellpadding=&quot;5&quot;>

</CFIF>

<tr><td>#myQuery.columnName1#</td><td>#myQuery.columnName2#</td></tr>


<CFSET myCurrentRow = myCurrentRow + 1>

<CFIF myCurrentRow GTE columnMax>
</table>
</td>
<CFSET myCurrentRow = 0>

</CFIF>

</CFOUTPUT>
</tr>
</table>

Hope it helps,
-Carl
 
good one carl

we think alike :)

use valign=&quot;top&quot; for the td holding the nested table, otherwise the last column will valigm middle if it's shorter than the others

one caveat: if any of the nested table data cells wrap, rows from adjacent nested tables won't &quot;line up&quot; but usually this doesn't matter


rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top