Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Horizontal Output 3

Status
Not open for further replies.

NetworkGuy101

IS-IT--Management
Aug 13, 2002
482
0
0
US
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?
 
There's always old reliable...

Code:
<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>&nbsp;</td>",leftover)#</tr>
  </cfif>
</cfoutput></table>

This will output all your rows.. The last cfif statement and the content inside it ensures that the table code in syntactically correct, so that you have no ugly empty cells.

To have this working, all you have to do is supply a query attribute for cfoutput and change "...stuff..." to the value you want to output..

HTH,
Tony

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
yep, thats old reliable for sure. the tricky part is when you want the results sorted verticly, not horizontaly :)

 
Imstillatwork,

Would you happen to know how to do this?
 
not of hand,

the way i did it before was to turn the recordset into as many arrays as you want columns, then in the first row, lay out the first item of each array, next row, the next item of each array...etc...

__________________________
| ar1[1] | ar2[1] | ar3[1] |
|--------+--------+--------|
| ar1[2] | ar2[2] | ar3[2] |
|--------+--------+--------|
| ar1[3] | ar2[3] | ar3[3] |
----------------------------

my explaination really sucks, basicly you need to loop through this as many times as your longest array is long, then clean up emtpy cells at the end. Lemme see what i can dig up.

 
Would there be a way for me to get the daterange for say October? Say I want to fond out how many days are in October 2004? Is there a tag that can do that or Will I have to make this up myself?
 
You can use the DaysInMonth() function.


DaysInMonth("date")




Hope This Helps!

Ecobb

&quot;My work is a game, a very serious game.&quot; - M.C. Escher
 
I have your display horizontally sort vertical answer. let me clean it up and I'll post it.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1959-2001)
 
I used a query here to make it versital for anyone, but you can easily change it to use just about anything

Code:
<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>

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1959-2001)
 
here is what i use to do my calenar
Code:
<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>

------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top