2 Replies Latest reply on Jan 21, 2015 6:07 AM by john_glynn

    Printing columns

    john_glynn

      I have not been able to accomplish this with CSS so I thought I would attempt it with CF.  I am trying to print a membership list for a yacht club in 2

      columns.  I first loop through the query results like so (lots of conditions to avoid empty lines):

       

      <cfloop query = "memberInformation">
                <cfif len(#phn_home#) GTE 8 || len(#phn_office#) GTE 8 || len(#phn_cell#) GTE 8 || len(#phn_spouse#) GTE 8>
              <cfset hasPhone = true>
              <cfelse>
              <cfset hasPhone = false>
            </cfif>
            <cfif len(#name_friendly#) GT 0 AND len(#name_spouse#) GT 0>
              <cfset friendlyName = '#name_friendly# & #name_spouse#'>
              <cfset hasSpouse = true>
              <cfelse>
              <cfset friendlyName = '#name_friendly#'>
              <cfset hasSpouse = false>
            </cfif>
            <div class="memberHolder" id=#member_id# mmbrNm='#friendlyName#' numVsts = #numvisits# hsSps=#hasSpouse#>
              <table class="memberRosterTable" width="600px" >
                <tr>
                  <td valign="top" align="left">
                    <p><b>#name_member#</b><br />
                      #address#<br />
                      <cfif len(reReplace(#phn_home#, "[[:space:]]", "", "ALL")) GTE 8>
                        (h) #phn_home#  
                      </cfif>
                      <cfif  len(reReplace(#phn_office#, "[[:space:]]", "", "ALL")) GTE 8>
                        (o) #phn_office#  
                      </cfif>
                      <cfif  len(reReplace(#phn_cell#, "[[:space:]]", "", "ALL"))GTE 8>
                        (c) #phn_cell#  
                      </cfif>
                      <cfif  len(reReplace(#phn_spouse#, "[[:space:]]", "", "ALL")) GTE 8>
                        (s) #phn_spouse#
                      </cfif>
                      <cfif hasPhone>
                        <br />
                      </cfif>
                      <cfif len(#email#) GTE 8>
                        Email: <a class="mailToLink" href="mailto:#email#" target="_top">#email#</a>  
                        <cfif len(#email_spouse#) GTE 8>
                          | <a class="mailToLink" href="mailto:#email_spouse#" target="_top">#email_spouse#</a>
                        </cfif>
                        <br />
                      </cfif>
                      <cfif len(reReplace(#memberSince#, "[[:space:]]", "", "ALL")) GTE 1>
                        Member since #memberSince#<br />
                      </cfif>
                      <cfif len(reReplace(#boat_name#, "[[:space:]]", "", "ALL")) GTE 1>
                        #boat_name#,
                      </cfif> 
                      <cfif len(reReplace(#boat_mooring#, "[[:space:]]", "", "ALL")) GTE 1>
                        #boat_mooring#<br />
                      </cfif>
                      <cfif len(reReplace(#boat_length#, "[[:space:]]", "", "ALL")) GTE 1>
                        Length: #boat_length#  Beam: #boat_beam#  Draft: #boat_draft#<br />
                      </cfif> 
                    </p>
                    <br /> <br /> </td>
                  <td valign="top"  width="150"><p><b>#friendlyName#</b></p></td>
                  
                </tr>
              </table>
            </div>
        </cfloop>
      

       

       

      This displays a very readable, single-column list.

       

       

      At this point I would like to format it into 2 columns so it can be printed, hole-punched and placed in a 5.5x8 3-ring

      binder.

       

       

      Any thoughts?

       

       

      Thank you!

      John

        • 1. Re: Printing columns
          BKBK Adobe Community Professional & MVP

          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.

          • 2. Re: Re: Printing columns
            john_glynn Level 1

            BKBK,

             

            Thank you for this is excellent and thoughtful response.  My tunnel vision was blinding me, I liked my collection of tables.  They seemed like safe little boxes holding member info, but in the end not very useful.  Your clever solution got me back on track:

             

            <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>

             

            From there I can skin this cat a number of ways, including the one you detailed above.  But I am thinking you are right, maybe getting rid of the tables altogether will open me up to a friendlier interaction with the CSS print media type and thus greater control over formatting for specific print jobs.  Kudos again for this generous reply!

             

            Cheers,

            John