(x)html compliant dynamic columns display
<cfquery datasource="dsn" name="q_your_query">
    SELECT id,name FROM your_table
</cfquery>

<table>
<cfoutput query="q_your_query">
    <cfif currentrow mod cols EQ 1>
        <!--- NEW ROW AND CELL--->
        <tr><td>
    <cfelse>
        <!--- NEW CELL --->
        <td>
    </cfif>
    DATA FOR THE CELL (#id#,#name#,etc..)
    </td>
    <cfif currentrow mod cols EQ 0>
        <!--- CLOSE ROW IF CURRENT ROW DIVISABLE EVENLY BY COLUMNS NEEDED--->
        </tr>
    <cfelseif currentrow EQ recordcount>
        <!--- FILL IN EXTRA BLANK CELLS FOR PROPER HTML COMPATABILITY ---->
        <!--- FIGURE OUT LOOP COUNT BASED ON RECORDCOUNT AND COLUMNS NEEDED --->
        <cfloop from="1" to="#cols - (recordcount mod cols)#" index="i">
            <td> </td>
        </cfloop>
        <!--- CLOSE ROW --->
        </tr>
    </cfif>
</cfoutput>
<!--- DONE! --->
</table>


All ColdFusion Tutorials By Author: Kevin S
  • (x)html compliant dynamic columns display
    This tutorial will show you how to display yout query results in a horizontal format x number of columns without loosing (x)html compliance. It may look slightly more complicated than others you may have seen, but this example provides full html and xhtml compatibility by cloasing all end tags and properly nesting td and tr.
    Author: Kevin S
    Views: 12,122
    Posted Date: Thursday, April 21, 2005
  • Side By Side Product Comparison
    This Tutorial will show you how to allow your web sites users to select items to compare side by side. Your items could be anything from products for sale to statistical information. Users can add and remove Items or Products to compare in a table. A great feature for sites seilling products, especially products with many variations for models in a series.
    Author: Kevin S
    Views: 8,713
    Posted Date: Thursday, January 12, 2006