Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 80307

Re: Printing columns

$
0
0

At first glance, something about the tag structure jumps out: <cfloop query="memberInformation"><table><tr></tr></table></cfloop>. That would display a table for every row, which seems inefficient.

 

The usual way to stucture such a display is: <table><cfloop query="memberInformation"><tr></tr></cfloop></table>. This would display all the rows in one table.

 

To display the rows in 2 columns, you could use either of the following strategies:

 

1) Display the rows of the first half of the result set in the first column, and those of the second half in the second column;

2) Display odd-numbered rows in the first column, and even-numbered rows in the second.

 

I shall explain only the first strategy in detail. You can figure out the second strategy yourself using similar steps.

 

Strategy 1:

 

<cfif memberInformation.recordcount MOD 2 is 0>

    <!--- Result set has even number of rows --->

    <cfset halfNumberOfRows= memberInformation.recordcount/2>

<cfelse>

    <!--- Result set has odd number of rows --->

    <cfset halfNumberOfRows= (memberInformation.recordcount+1)/2>

</cfif>

 

<table border="1">

<cfloop from="1" to="#halfNumberOfRows#" index="row">       

<cfoutput>

<tr>

<td>(Column 1 content)</td><td></td>

<td> </td> <!--- space separating the columns --->

<td>(Column 2 content)</td><td></td>

</tr>

</cfoutput>

</cfloop>

</table>

 

Column 1 content

The row numbers for this column run from 1 to memberInformation.recordcount/2 or (memberInformation.recordcount+1)/2. The content is just all code per row in your above post, with the exception that you now have to begin by replacing each database column name by its array equivalent. You will then use the corresponding  'local' values instead.That is, something like this for Column 1:

 

<cfset local = structNew()>

<cfset local.phn_home = memberInformation["phn_home"][row]>

<cfset local.phn_office = memberInformation["phn_office"][row]>

<cfset local.phn_cell = memberInformation["phn_cell"][row]>

<cfset local.phn_spouse = memberInformation["phn_spouse"][row]>

<cfset local.name_friendly = memberInformation["name_friendly"][row]>

<cfset local.name_spouse = memberInformation["name_spouse"][row]>

<cfset local.member_id = memberInformation["member_id"][row]>

<cfset local.numvisits = memberInformation["numvisits"][row]>

<cfset local.name_member = memberInformation["name_member"][row]>

<cfset local.address = memberInformation["address"][row]>

<cfset local.email = memberInformation["email"][row]>

<cfset local.email_spouse = memberInformation["email_spouse"][row]>

<cfset local.member_since = memberInformation["member_since"][row]>

<cfset local.boat_name = memberInformation["boat_name"][row]>

<cfset local.boat_mooring = memberInformation["boat_mooring"][row]>

<cfset local.boat_length = memberInformation["boat_length"][row]>

<cfset local.boat_beam = memberInformation["boat_beam"][row]>

<cfset local.boat_draft = memberInformation["boat_draft"][row]>

 

 

Column 2 content

The row numbers for this column run from memberInformation.recordcount/2 +1 or (memberInformation.recordcount+1)/2 + 1 to memberInformation.recordcount. The replacements per row for Column 2 are:

 

<cfset r2 = row + halfNumberOfRows>

<cfset local.phn_home = memberInformation["phn_home"][r2]>

<cfset local.phn_office = memberInformation["phn_office"][r2]>

<cfset local.phn_cell = memberInformation["phn_cell"][r2]>

<cfset local.phn_spouse = memberInformation["phn_spouse"][r2]>

<cfset local.name_friendly = memberInformation["name_friendly"][r2]>

<cfset local.name_spouse = memberInformation["name_spouse"][r2]>

<cfset local.member_id = memberInformation["member_id"][r2]>

<cfset local.numvisits = memberInformation["numvisits"][r2]>

<cfset local.name_member = memberInformation["name_member"][r2]>

<cfset local.address = memberInformation["address"][r2]>

<cfset local.email = memberInformation["email"][r2]>

<cfset local.email_spouse = memberInformation["email_spouse"][r2]>

<cfset local.member_since = memberInformation["member_since"][r2]>

<cfset local.boat_name = memberInformation["boat_name"][r2]>

<cfset local.boat_mooring = memberInformation["boat_mooring"][r2]>

<cfset local.boat_length = memberInformation["boat_length"][r2]>

<cfset local.boat_beam = memberInformation["boat_beam"][r2]>

<cfset local.boat_draft = memberInformation["boat_draft"][r2]>

 

To keep your code maintainable, you could implement these replacements as a cfinclude.

 

Having said that, I should add that the combination of <div> and CSS has many advantages over <table> at rendering tables. Should you reconsider <div> and CSS, here is an example.


Viewing all articles
Browse latest Browse all 80307

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>