[thelist] Cold Fusion -- looping records in 3 columns

Joshua Olson joshua at waetech.com
Fri Feb 28 21:37:01 CST 2003


I whipped up some code for handling the columns in CF:

<cfset form.columns = "5">

<cfquery name="get_cities" datasource="sample"  dbtype="OLEDB">
  SELECT city
  FROM tableofcities
</cfquery>

<cfset checkpoints = ArrayNew(1)>
<cfloop index="col" from="1" to="#form.columns#">
  <cfset checkpoints[col] = "0">
</cfloop>

<cfset width = Int(100 / form.columns) & "%">
<cfset col = "1">

<div style="width: 100%;">
<cfoutput query="get_cities">
  <cfif currentrow IS "1">
    <div style="float: left; padding: 15px; width: #width#">
  </cfif>
  <cfif currentrow GT (recordcount * col / form.columns)
        AND NOT checkpoints[col]>
    </div>
    <div style="float: left; padding: 15px; width: #width#">
    <cfset checkpoints[col] = "1">
    <cfset col = col + "1">
  </cfif>
  #city#<br />
  <cfif currentrow IS recordcount>
   </div>
  </cfif>
</cfoutput>
</div>

~~~~~~~~~~~~~~~~~~~~~

Just change the form.columns value to change the number of displayed
columns.

HTH,
-joshua




More information about the thelist mailing list