[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

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

<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 currentrow GT (recordcount * col / form.columns)
        AND NOT checkpoints[col]>
    <div style="float: left; padding: 15px; width: #width#">
    <cfset checkpoints[col] = "1">
    <cfset col = col + "1">
  #city#<br />
  <cfif currentrow IS recordcount>


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


More information about the thelist mailing list