/ Published in: ColdFusion
coldfusion snippet to output a query recordset into multiple columns
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!--- Number of columns per row ---> <cfset NumCols = 2> <cfset tableBGColor = "99AF26"> <!--- any hex value - --> <cfset tablealign = "left"> <!--- right, left, center ---> <cfset trBGColor = "D6E0A1"> <!--- any hex value ---> <cfset tdBGColor = "D6E0A1"> <!--- any hex value ---> <cfset tdHighlightColor = "D6E0A1"> <!--- any hex value ---> <cfset tdEmptyCell = "D6E0A1"> <!--- any hex value ---> <cfset table_cellpadding = 4> <!--- numerical value ---> <cfset table_cellspacing = 1> <!--- numerical value ---> <cfset table_width = 455> <!--- numerical value, (1-100 for percent width)---> <cfset table_width_type = ""> <!--- "%" for percentage or leave blank for pixel width ---> <cfset query = "getSponsors"> <!--- query name ---> <cfset ColWidth = Fix(100/NumCols)> <cfoutput> <table border="0" cellpadding="#table_cellpadding#" cellspacing="#table_cellspacing#" width="#table_width##table_width_type#" bgcolor="#tableBGColor#" align="#tablealign#"> <tr valign="top" bgcolor="#trBGColor#"> <cfloop query="#query#"> <td align="center" width="#ColWidth#%" bgcolor="#tdBGColor#"> <!--- begin: cells containing content---> <!--- end: cells containing content---> </td> <cfif (Evaluate(query&".CurrentRow") MOD NumCols) IS 0 AND (Evaluate(query&".CurrentRow") NEQ Evaluate(query&".RecordCount"))> </tr> <tr valign="top" bgcolor="#trBGColor#"> </cfif> </cfloop> <cfif Evaluate(query&".RecordCount") MOD NumCols GT 0> <cfset Variables.NumMissingCells = NumCols - (Evaluate(query&".RecordCount") MOD NumCols)> <cfloop from="1" to="#Variables.NumMissingCells#" index="iCell"> <!--- begin: padding cells ---> <!--- end: padding cells ---> </cfloop> </cfif> </tr> </table> <br> </cfoutput> <!--- Number of columns per row --->