Posted By

dreamstarter on 07/15/14


Tagged

query ColdFusion multiple columns


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dreamstarter


Query output into multiple columns


 / Published in: ColdFusion
 

coldfusion snippet to output a query recordset into multiple columns

  1. <!--- Number of columns per row --->
  2. <cfset NumCols = 2>
  3. <cfset tableBGColor = "99AF26"> <!--- any hex value - -->
  4. <cfset tablealign = "left"> <!--- right, left, center --->
  5. <cfset trBGColor = "D6E0A1"> <!--- any hex value --->
  6. <cfset tdBGColor = "D6E0A1"> <!--- any hex value --->
  7. <cfset tdHighlightColor = "D6E0A1"> <!--- any hex value --->
  8. <cfset tdEmptyCell = "D6E0A1"> <!--- any hex value --->
  9. <cfset table_cellpadding = 4> <!--- numerical value --->
  10. <cfset table_cellspacing = 1> <!--- numerical value --->
  11. <cfset table_width = 455> <!--- numerical value, (1-100 for percent width)--->
  12. <cfset table_width_type = ""> <!--- "%" for percentage or leave blank for pixel width --->
  13. <cfset query = "getSponsors"> <!--- query name --->
  14. <cfset ColWidth = Fix(100/NumCols)>
  15. <cfoutput>
  16. <table border="0" cellpadding="#table_cellpadding#" cellspacing="#table_cellspacing#" width="#table_width##table_width_type#" bgcolor="#tableBGColor#" align="#tablealign#">
  17. <tr valign="top" bgcolor="#trBGColor#">
  18. <cfloop query="#query#">
  19. <td align="center" width="#ColWidth#%" bgcolor="#tdBGColor#">
  20. <!--- begin: cells containing content--->
  21. <a href="?sid=#spn_id#" title="Click here to view more information about this sponsor.">#spn_name#</a><br>
  22. <!--- end: cells containing content--->
  23. </td>
  24. <cfif (Evaluate(query&".CurrentRow") MOD NumCols) IS 0 AND (Evaluate(query&".CurrentRow") NEQ Evaluate(query&".RecordCount"))>
  25. </tr>
  26. <tr valign="top" bgcolor="#trBGColor#">
  27. </cfif>
  28. </cfloop>
  29. <cfif Evaluate(query&".RecordCount") MOD NumCols GT 0>
  30. <cfset Variables.NumMissingCells = NumCols - (Evaluate(query&".RecordCount") MOD NumCols)>
  31. <cfloop from="1" to="#Variables.NumMissingCells#" index="iCell">
  32. <!--- begin: padding cells --->
  33. <td bgcolor="#tdEmptyCell#">&nbsp;</td>
  34. <!--- end: padding cells --->
  35. </cfloop>
  36. </cfif>
  37. </tr>
  38. </table>
  39. <br>
  40. </cfoutput>
  41. <!--- Number of columns per row --->

Report this snippet  

You need to login to post a comment.