HOME | FERGUSON Digital Blog

Using MOD 4 With CFOUTPUT (redux)

ColdFusion Add comments

Yesterday I posted about how you could use the "MOD (Modulo) with CFOUTPUT to build a table to display four pairs of repeating data from a query structure" and thanks to a response by Michael Zock, I realized that my example was not proofread so here is a redux example of Modulo driven column display from a query.

<!---USE NORTHWIND DATABASE TO BUILD QUERY--->
<cfquery name="GetInfo" datasource="Northwind">
   SELECT OrderID, ShipName
   FROM Orders
</cfquery>

<table border="1" cellpadding="0" cellspacing="0">
   <tr>
      <!---LOOP FOUR TIMES TO BUILD REPEATING HEADER--->
      <cfloop index="LoopIndex" from="1" to="4">
         <th>Order ID</th>
         <th>Ship Name</th>
      </cfloop>
   </tr>
   <!---OUTPUT QUERY--->
   <cfoutput query="GetInfo">
      <!---USE MODULO 4 TO DETERMINE IF CURRENT RECORD DIVISIBLE BY FOUR FOR TR--->
      <cfif GetInfo.CurrentRow MOD 4 EQ 1 OR GetInfo.CurrentRow EQ 1><tr></cfif>
         <td width="5%">#GetInfo.OrderID#</td>
         <td width="20%">#GetInfo.ShipName#</td>
      <!---USE MODULO 4 AND CHECK IF END OF QUERY FOR CLOSING TR OF EACH ROW--->
      <cfif GetInfo.CurrentRow MOD 4 EQ 0 OR GetInfo.RecordCount EQ GetInfo.CurrentRow>
         <!---CHECK IF LAST ROW HAS LESS THAN 4 RESULTS TO PAD TABLE--->
         <cfloop index="LoopIndex" from="1" to="#GetInfo.CurrentRow MOD 4#">
            <td width="5%"> </td>
            <td width="20%"> </td>
         </cfloop>
         </tr>
      </cfif>
   </cfoutput>
</table>
<br /><br />
<!---EXAMPLE REPEATED WITH QUERY MAXROWS 16 (4x4) TO PROVE CLOSING TR AND QUERY END CHECK--->
<table border="1" cellpadding="0" cellspacing="0">
   <tr>
      <cfloop index="LoopIndex" from="1" to="4">
         <th>Order ID</th>
         <th>Ship Name</th>
      </cfloop>
   </tr>
   <cfoutput query="GetInfo" maxrows="16">
      <cfif GetInfo.CurrentRow MOD 4 EQ 1 OR GetInfo.CurrentRow EQ 1><tr></cfif>
         <td width="5%">#GetInfo.OrderID#</td>
         <td width="20%">#GetInfo.ShipName#</td>
      <cfif GetInfo.CurrentRow MOD 4 EQ 0 OR GetInfo.RecordCount EQ GetInfo.CurrentRow>
         <cfloop index="LoopIndex" from="1" to="#GetInfo.CurrentRow MOD 4#">
            <td width="5%"> </td>
            <td width="20%"> </td>
         </cfloop>
         </tr>
      </cfif>
   </cfoutput>
</table>

I hope this more complete example better illustrates a use for the MOD (Modulo) than just alternating row colors for table rows!

If you find this post useful please leave a comment and let me know how you used the information.

Download zipped example HERE.

19 responses to “Using MOD 4 With CFOUTPUT (redux)”

  1. Kevin on Welcome to <strong><a href="http://www.christianlouboutinbootsoutlet.net/">Christian Louboutin Outlet</a></strong> store,we specialize in seeling <strong><a href="http://www.christianlouboutinbootsoutlet.net/">Christian Louboutin Boots</a></strong> directly from factory with 100% quality guarantee,buy <strong><a href="http://www.christianlouboutinbootsoutlet.net/">Cheap Christian Louboutin</a></strong>here with free shipping.
  2. Kevin on Welcome to [b][url=http://www.christianlouboutinbootsoutlet.net/]Christian Louboutin Outlet[/url][/b] store,we specialize in seeling [b][url=http://www.christianlouboutinbootsoutlet.net/]Christian Louboutin Boots[/url][/b] directly from factory with 100% quality guarantee,buy [b][url=http://www.christianlouboutinbootsoutlet.net/]Cheap Christian Louboutin[/url][/b]here with free shipping.
  3. Kevin on http://www.christianlouboutinbootsoutlet.net
  4. Christian Louboutin Boots on nice article,thanks for your posting
  5. cheapbeatsbydre on cheap beats by dre This is the interpretation of the article is very good, monster headphones pass this article I read you can have different harvest, Dre Lady Gaga Headphones good article introduced to share the happiness, Dre New style Beats By Dre come in and see not cost you too much time but can let you learn a lotDre Beats By Dre black.
    http://www.salescheapbeatsbydre.com/
  6. discountnorthface on north face outlet read this article after, cheap north face have a lot of new things is our reality didn't learn north face shop, the article is well written, Mens North Face Apex Bionic key points, concise content Womens North Face Apex Bionic .
    http://www.northfacehonsale.org/
  7. Asics Gel Shoes on Very nice article,thanks for your sharing.
  8. Monster Energy Hats on Monster Energy Hats
  9. NBA Hats on NBA Hats NBA Hats
  10. moncler mens sweaters on moncler mens sweaters
  11. Randhil on I really wish there were more aritlces like this on the web.
  12. security systems on The storeroom units are observing over by the worker, and together he and the customer have the only right of entry to the element. Self storage space ability operators typically provide computer-controlled right of entry to hire liberty region and many often use safety cameras for watch. Thanks
  13. Christian Louboutin Outlet on this was a really nice post. In thought I wish to put in writing like this additionally ?taking time and precise effort to make a very good article?but what can I say?I procrastinate alot and in no way appear to get one thing done.
  14. xylzvdvn on uqznyfbw
  15. sopxntof on ekbfao
  16. Payday Loan on ujfuuvai http://onlineukpaydayloans.co.uk/ Payday Loans UK >:]] <a href="http://fastuspaydayloans.com/ ">payday loans</a> >:-[ [url=http://fastpaydayloansus.com/]fast payday loans[/url] 1862
  17. Cheap Jordan Sneakers on In thought I wish to put in writing like this additionally ?taking time and precise effort to make a very good article?but what can I say?
  18. Payday Loans UK on udkjhpyx
  19. cialis sale on vlnnxg

Leave a Reply




© Copyright 1997-2012, All Rights Reserved Coldfusion and MS SQL2008
Powered by Mango Blog.   Design by FERGUSON Digital
o:Event name="beforeHtmlBodyEnd" />