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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

output asp script multiple times

Status
Not open for further replies.

tyutghf

Technical User
Apr 12, 2008
258
GB
I have an asp calendar I have modified (taken a base version from a script website) that displays a calendar, looks at a database and highlights days with an event behind them.

The script outputs just one calendar to the screen, is it possible to make it output three at a time

eg current month is August so August, September and October are displayed. Press next to advance the months on.

Here is my script

Code:
<%
	'------------------------------------------------------------
	' This function finds the last date of the given month
	'------------------------------------------------------------
	Function GetLastDay(intMonthNum, intYearNum)
		Dim dNextStart
		If CInt(intMonthNum) = 12 Then
			dNextStart = CDate( "1/1/" & intYearNum)
		Else
			dNextStart = CDate(intMonthNum + 1 & "/1/" & intYearNum)
		End If
		GetLastDay = Day(dNextStart - 1)
	End Function
	
	'-------------------------------------------------------------------------
	' This routine prints the individual table divisions for days of the month
	'-------------------------------------------------------------------------
	Sub Write_TD(sValue, sClass)
		Response.Write "		<td class='" & sClass & "'>" & sValue & "</TD>" & vbCrLf
	End Sub


	' Constants for the days of the week
	Const cFRI = 1, cSAT = 2, cSUN = 3, cMON = 4, cTUE = 5, cWED = 6, cTHU = 7
	
	' Get the name of this file
	sScript = Request.ServerVariables("SCRIPT_NAME")
	
	' Check for valid month input
	If IsEmpty(Request("MONTH")) OR NOT IsNumeric(Request("MONTH")) Then
	  datToday = Date()
	  intThisMonth = Month(datToday)
	ElseIf CInt(Request("MONTH")) < 1 OR CInt(Request("MONTH")) > 12 Then
	  datToday = Date()
	  intThisMonth = Month(datToday)
	Else
	  intThisMonth = CInt(Request("MONTH"))
	End If
	
	' Check for valid year input
	If IsEmpty(Request("YEAR")) OR NOT IsNumeric(Request("YEAR")) Then
	  datToday = Date()
	  intThisYear = Year(datToday)
	Else
	  intThisYear = CInt(Request("YEAR"))
	End If

	strMonthName = MonthName(intThisMonth)
	datFirstDay = DateSerial(intThisYear, intThisMonth, 1)
	intFirstWeekDay = WeekDay(datFirstDay, vbFriday)
	intLastDay = GetLastDay(intThisMonth, intThisYear)
	
	' Get the previous month and year
	intPrevMonth = intThisMonth - 1
	If intPrevMonth = 0 Then
		intPrevMonth = 12
		intPrevYear = intThisYear - 1
	Else
		intPrevYear = intThisYear	
	End If
	
	' Get the next month and year
	intNextMonth = intThisMonth + 1
	If intNextMonth > 12 Then
		intNextMonth = 1
		intNextYear = intThisYear + 1
	Else
		intNextYear = intThisYear
	End If

	' Get the last day of previous month. Using this, find the sunday of
	' last week of last month
	LastMonthDate = GetLastDay(intLastMonth, intPrevYear) - intFirstWeekDay + 2
	NextMonthDate = 1

	' Initialize the print day to 1  
	intPrintDay = 1

	' Open a record set of schedules
	Set Rs = Server.CreateObject("ADODB.RecordSet")
	
	' These dates are used in the mySQL database, if dates in different format change this bit and maybe locale above
	dFirstDay = intThisYear & "-" & intThisMonth & "-1"
	dLastDay 	= intThisYear & "-" & intThisMonth & "-" & intLastDay

	sSQL = 	"SELECT DISTINCT * FROM t_table WHERE " & _
					"(Start_Date >='" & dFirstDay & "' AND Start_Date <= '" & dLastDay & "') " & _
					"OR " & _
					"(End_Date >='" & dFirstDay & "' AND End_Date <= '" & dLastDay & "') " & _
					"OR " & _
					"(Start_Date < '" & dFirstDay & "' AND End_Date > '" & dLastDay & "' )"  & _
					" AND booked = '1' ORDER BY Start_Date"

	'Response.Write sSQL

	set rs = server.CreateObject("ADODB.RECORDSET")
	rs.Open sSQL,objConn
	

%>


<br /><br />

	<table id='eventcalendar' BORDER="0" CELLPADDING="0" CELLSPACING="0">
		<tr class='eventcalendardate'>
			<td align="left" valign="middle"><a href="<% =sScript%>?month=<% =IntPrevMonth %>&amp;year=<% =IntPrevYear %>" class='white'><<</a></td>
			<td COLSPAN="5" align="center" valign="middle"><% = strMonthName & " " & intThisYear %></td>
			<td align="right" valign="middle"><a href="<% =sScript %>?month=<% =IntNextMonth %>&amp;year=<% =IntNextYear %>" class='white'>>></a></td>
		</tr>
	  <tr>
			<th>F</th>
			<th>S</th>
			<th>S</th>
			<th>M</th>
			<th>T</th>
			<th>W</th>
			<th>T</th>
	  </tr>
			<%
			' Initialize the end of rows flag to false
			EndRows = False
			Response.Write vbCrLf
			
			' Loop until all the rows are exhausted
		 	Do While EndRows = False
				' Start a table row
				Response.Write "	<tr align='center'>" & vbCrLf
				' This is the loop for the days in the week
				For intLoopDay = cFRI To cTHU
					' If the first day is not friday then print the last days of previous month in grayed font
					If intFirstWeekDay > cFRI Then
						Write_TD LastMonthDate, "non"
						LastMonthDate = LastMonthDate + 1
						intFirstWeekDay = intFirstWeekDay - 1
					' The month starts on a sunday	
					Else
						' If the dates for the month are exhausted, start printing next month's dates
						' in grayed font
						If intPrintDay > intLastDay Then
							Write_TD NextMonthDate, "non"
							NextMonthDate = NextMonthDate + 1
							EndRows = True 
						Else
							' If last day of the month, flag the end of the row
							If intPrintDay = intLastDay Then
								EndRows = True
							End If
							
							dToday = CDate(intThisMonth & "/" & intPrintDay & "/" & intThisYear)  
							dTodayFormat = CDate(intPrintDay & "/" & intThisMonth & "/" & intThisYear) 'added to display the date link in usa for the events page.
							
							If NOT Rs.EOF Then
								' Set events flag to false. This means the day has no event in it
								bEvents = False
							  Do While NOT Rs.EOF AND bEvents = False
									' If the date falls within the range of dates in the recordset, then 
									' the day has an event. Make the events flag True
							    If dToday >= Rs("Start_Date") AND dToday <= Rs("End_Date") Then
										' Print the date in a highlighted font
							      'this one has a link, just formattingWrite_TD "<A HREF=events.asp?date="& Server.URLEncode(dToday) & " TARGET='_blank'> " & intPrintDay & "</A>", "event"
													   if rs("booked") = "1" then
													   Write_TD "" & intPrintDay & "", "event"
																else
																Write_TD "<a href='#'  onclick='getPrices("""& rs("Event_ID") & """)'>" & intPrintDay & "</a>", "noevent"
																end if
													
										bEvents = True
									' If the Start date is greater than the date itself, there is no point
									' checking other records. Exit the loop	
							    ElseIf dToday < Rs("Start_Date") Then
										Exit Do
									' Move to the next record
									Else	
								    Rs.MoveNext
									End If
							  Loop
								' Checks for that day
								Rs.MoveFirst
							End If
							
							' If the event flag is not raise for that day, print it in a plain font
							If bEvents = False Then
							       if intLoopDay = cFRI then
								      Write_TD "<a href='#'  onclick='getPrices("""& Server.URLEncode(dToday) & """)'>" & intPrintDay & "</a>", "noevent"
														else
														Write_TD "" & intPrintDay & "", "noevent"
														end if
							End If
						End If 
						
						' Increment the date. Done once in the loop.
						intPrintDay = intPrintDay + 1
					End If
				
				' Move to the next day in the week
				Next
				Response.Write "	</tr>" & vbCrLf
				
			Loop 
			Rs.Close
	 	Set Rs = Nothing
		%>
	</table>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top