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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coldfusion Table Formating?

Status
Not open for further replies.

tjg

Programmer
May 7, 2001
3
US
I am trying to create a table that displays 4 results per row. The problem I am having is that I want the results to be centered within each row. For example, If I get 9 results for a query, a table is created with two rows of 4 results and a third row with the ninth result. This ninth result gets aligned to the left of the row and I would like it to be centered in the row. If this page was static I could just use a colspan to get the one cell on the third row to colspan 4 colums. I need a colspan that functions when a row has less than 4 results in it, and that will set the colspan according to the number of results that it has.

so if a row had two results a colspan of 2 for each result would make them centered to the rest of the table. How can I create a dynamic colspan that is able to do this?

Below is the code I have been using:

<cfoutput query=&quot;logo&quot;>
<td align=&quot;center&quot;><img src=&quot;#SFileName#&quot; border=&quot;0&quot; alt=&quot;#Description#&quot;></a></td>
<cfif gwpr.currentRow MOD 4 eq 0>
</tr><tr>
</cfif>
</cfoutput>
 
<cfparam name=&quot;attributes.counter&quot; default=&quot;0&quot;>
<cfset variables.picList = structKeyList(request.picture)>
<table width=&quot;600&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; align=&quot;center&quot;>
<tr>
<cfoutput query=&quot;logo&quot;>
<cfset attributes.counter = attributes.counter + 1>
<td valign=&quot;bottom&quot; align=&quot;center&quot;class=&quot;bodyText&quot;><img src=&quot;#SFileName#&quot; border=&quot;0&quot; alt=&quot;#Description#&quot;></td>
<cfif attributes.counter MOD 4>
</tr>
</table>
<table width=&quot;600&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; align=&quot;center&quot;>
<tr>
<td height=&quot;10&quot;><img src=&quot;images/dot.gif&quot; width=&quot;1&quot; height=&quot;5&quot; border=&quot;0&quot;></td>
</tr>
<tr>
<cfset attributes.counter = 0>
</cfif>
</cfoutput>
</tr>
</table> ------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
tjg, you can continue to use colspan, but there's a catch

the MOD 4 technique is fine for rows at the front of the table, but when you get near the end, you have to be careful

query.recordCount MOD 4 will tell you how many recods are &quot;left over&quot; (so to speak)

i.e. if your query returns 17 records, 17 MOD 4 is 1, so there's 1 record left over, so you need colspan=4 for the last td

so you have to detect when you are just about to do the last table row

you can get this from

query.currentRow >= (query.recordCount MOD 4) * 4

however, as i said, there's a catch

if there's 1 record left over, you can easily do

<tr><td colspan=4>foo</td></tr>

and if there's two records left over, you could do

<tr><td colspan=2>foo</td>><td colspan=2>bar</td></tr>

but (finally) here's the catch -- what do you do if there's 3 left over?

my advice? forget about this, just lay the records into 4 table cells, left to right

the code will stay simple and you can move on to other things...


rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top