NetworkGuy101
IS-IT--Management
Is there a way I can set a certain number of record to output horizontally and once that number is reached it will start a new row. Like a calender row of 7 unit day 30 is reached?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<cfset iCount=0>
<table><cfoutput...>
<cfset icount=icount+1>
<cfif icount eq 1><tr></cfif>
<td>...stuff...</td>
<cfif icount eq 7><cfset icount eq 0></tr></cfif>
</cfoutput>
<cfoutput>
<cfif icount neq 0>
<cfset leftover=7-icount>
#repeatstring("<td> </td>",leftover)#</tr>
</cfif>
</cfoutput></table>
<cfquery name = "myQuery" datasource = "#application.dsn#">
Your query here
</cfquery>
<!--- set the number of colums you wish to have --->
<cfset cols = 4>
<!--- get the number of rows so you know what record to display at the top of the next row --->
<cfset totalRows = ceiling(myQuery.RecordCount / cols)>
<!--- set inital record to 1 --->
<cfset output = 1>
<table width = "100%" border="0" align="center" cellpadding="2" cellspacing = "2">
<!--- loop through the rows --->
<cfloop from = "1" to = "#totalRows#" index = "thisrow">
<tr>
<!--- create cols --->
<cfloop from = "1" to = "#cols#" index = "thisCol">
<!--- the width in the table cell will dynamicaly calculated to
evenly distribute the cells. ie if cols = 4 100/4 will make the cells
25% of the table --->
<td width = "<cfoutput>#numberformat(evaluate(100/cols), 99)#</cfoutput>%" align="center" nowrap style = "border: 1px solid #ccc;">
<!--- check to make sure you're not accessing a record out of range --->
<cfif output lte myQuery.recordCount>
<cfoutput>#myQuery.myField[output]#</cfoutput>
<cfelse>
<!--- use br to display an empty cell --->
<br>
</cfif>
<!--- increment output to the next record which should be displayed at the top of the next col --->
<cfset output = output + totalRows>
</td>
</cfloop>
<!--- set the output to the first col of the next row --->
<cfset output = thisRow + 1>
</tr>
</cfloop>
</table>
<cfset request.imgSrc = "images/">
<cfset theDate=dateAdd("M",-1,now())>
<cfset theMonth=month(theDate)>
<cfset theYear=year(theDate)>
<cfscript>
firstDay = CreateDate(theYear,theMonth,1);
startDay = DayOfWeek(firstDay);
lastDay = DaysInMonth(firstDay);
</cfscript>
<cfoutput>
<table cellpadding="0" cellspacing="0" border="0" width="148">
<tr>
<td>#MonthAsString(theMonth)# #TheYear#</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" width="148">
<tr>
<td colspan="3" width="148" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
</tr>
<tr>
<td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
<td width="146">
<table cellpadding="0" cellspacing="0" border="0" width="146">
<tr>
<td width="146" valign="top">
<table cellpadding="0" cellspacing="0" border="0" width="146">
<tr bgcolor="silver">
<td align="center" width="20">Su</td>
<td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
<td align="center" width="20">M</td>
<td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
<td align="center" width="20">T</td>
<td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
<td align="center" width="20">W</td>
<td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
<td align="center" width="20">Th</td>
<td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
<td align="center" width="20">F</td>
<td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
<td align="center" width="20">Sa</td>
</tr>
<tr>
<td colspan="13" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
</tr>
<tr bgcolor="white">
<cfloop index="i" from="0" to="#val(startDay-2)#">
<td><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
<td width="1" bgcolor="DDDDDD"><img src="#request.imgSrc#dot.gif" width="1" height="15" border="0"></td>
</cfloop>
<cfset j = startDay-1>
<cfloop index="i" from="1" to="#lastDay#">
<cfset j = j + 1>
<td align="center">#i#</td>
<cfif j LTE 6><td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="15" border="0"></td></cfif>
<cfif j GT 6>
</tr>
<tr>
<td colspan="13" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
</tr>
<tr bgcolor="white">
<cfset j = 0>
</cfif>
</cfloop>
<!--- fill out the remander of the calendar-------------------------------------------->
<cfloop from="#j#" to="6" index="foo">
<td align="center"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
<cfif foo LT 6><td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td></cfif>
</cfloop>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="1" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
</tr>
<tr>
<td colspan="3" width="148" bgcolor="black"><img src="#request.imgSrc#dot.gif" width="1" height="1" border="0"></td>
</tr>
</table>
</td>
</tr>
</table>
</cfoutput>