Skip to main content
Inspiring
July 16, 2010
Question

Format Table data dynamically...?

  • July 16, 2010
  • 1 reply
  • 389 views

I am trying output data into three columns June, July, August. The following code somewhat accomplishes it, however, I would like to eliminate the blank cells within the columns and have the July data start on the top line (next to June) and the same with the August data.

Here is my existing code:

  <table class="tabTable">
          <tr>
            <td width="33%" colspan="2"><h3>June</h3></td>
            <td width="33%" colspan="2"><h3>July</h3></td>
            <td width="33%" colspan="2"><h3>August</h3></td>
          </tr>
          <tr class="odd">
            <td><h3 class="blue">Date</h3></td>
            <td><h3 class="blue">Hours</h3></td>
            <td><h3 class="blue">Date</h3></td>
            <td><h3 class="blue">Hours</h3></td>
            <td><h3 class="blue">Date</h3></td>
            <td><h3 class="blue">Hours</h3></td>
          </tr>
         
          <cfquery name="EWDays" datasource="xyz">
          Select id, ewDate, ewHours
          from tblDates   
          order by id asc
          </cfquery>
          <cfoutput query="EWDays">             
              <cfset PDate = #DateFormat(ewDate,"mm/dd/yy")#>
              <cfset PHours = #Trim(ewHours)#>
             
            <cfset bgc = IIf((EWDays.currentRow MOD 2) eq 0, DE("odd"), DE("")) >
            <cfset June = IIf((Month(PDate)) eq 6, DE("<td>#PDate#</td><td>#PHours#</td>"), DE("<td></td><td></td>")) >
            <cfset July = IIf((Month(PDate)) eq 7, DE("<td>#PDate#</td><td>#PHours#</td>"), DE("<td></td><td></td>")) >
            <cfset August = IIf((Month(PDate)) eq 8, DE("<td>#PDate#</td><td>#PHours#</td>"), DE("<td></td><td></td>")) >
              <tr class="#bgc#">
               #June# #July# #August#            
    </tr>            
   </cfoutput>
        </table>

Any ideas?

Message was edited by: Jim Stout

    This topic has been closed for replies.

    1 reply

    Inspiring
    July 17, 2010

    First, order your query by the date, not the id.

    Second, use nested tables.