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

Displaying a calendar with links 1

Status
Not open for further replies.

bluesauceuk

Programmer
Joined
Jan 1, 2001
Messages
73
Location
GB
Hiya,

I need to display a calendar (without the use of a custom tag)... of the current month with next month and previous buttons..

Then I need to be able to add in an event... and then this should appear as a link...

For example: a table like so...
------------------------------
S M T W T F S
1 2 3 4 5 6
7 8 _9_ 10 11 12 13
14 15 16 17
-------------------------------
[<<Jan] Feburary [Mar>>]
-------------------------------

..... as you see the 9th of feb is a link to an event...

Can anyone help.... urgently?

Cheers

Mark [mark [at] bluesauce.co.uk] ;-)



 
Here, Mark. Try this:

<!--- Inputs required: DisplayDate (ODBC Date/Time object) --->
<CFSET TodaysDate = CreateODBCDate(Now())>
<CFSET ThisMonth = Month(TodaysDate)>
<CFSET ThisDay = Day(TodaysDate)>

<CFOUTPUT>
<TABLE CLASS=&quot;Reserve&quot; WIDTH=&quot;200&quot; CELLPADDING=&quot;3&quot; BGCOLOR=&quot;#Application.Lighter#&quot; BORDER=&quot;1&quot; BORDERCOLOR=&quot;#Application.DarkColor#&quot;>
<TR BGCOLOR=&quot;#Application.MediumColor#&quot;>
<TD COLSPAN=&quot;7&quot; ALIGN=&quot;center&quot;>
<B>#MonthAsString(Month(DisplayDate))# #Year(DisplayDate)#</B>
</TD>
</TR>
</CFOUTPUT>
<!--- Now we need to display the weeks of the month. --->
<!--- The logic here is not too complex. We know that every 7 days we need to start a new table row. The only hard part is figuring out how much we need to pad the first and last row. To figure out how much we need to pad, we just figure out what day of the week the first of the month is. if it is wednesday, then we need to pad for sunday,monday, and tuesday. 3 days. --->
<TR>
<CFSET FIRSTOFMONTH=CreateDate(Year(DisplayDate),Month(DisplayDate),1)>
<CFSET TOPAD=DayOfWeek(FIRSTOFMONTH) - 1>
<CFSET PADSTR=RepeatString(&quot;<TD> </TD>&quot;,TOPAD)>
<CFOUTPUT>#PADSTR#</CFOUTPUT>
<CFSET DW=TOPAD>
<CFLOOP INDEX=&quot;X&quot; FROM=&quot;1&quot; TO=&quot;#DaysInMonth(DisplayDate)#&quot;>
<TD ALIGN=&quot;center&quot;><CFOUTPUT><A HREF=&quot;#PageLink#?Room=#URL.Room#&DisplayDate=#DisplayDate#&ThisDate=#X#&quot;>#X#</A></CFOUTPUT></TD>
<CFSET DW=DW + 1>
<CFIF DW EQ 7>
</TR>
<CFSET DW=0>
<CFIF X LT DaysInMonth(DisplayDate)><TR></CFIF>
</CFIF>
</CFLOOP>
<!---
Now we need to do a pad at the end, just to make our table &quot;proper&quot; we can figure out how much the pad should be by examining DW --->
<CFSET TOPAD=7 - DW>
<CFIF TOPAD LT 7>
<CFSET PADSTR=RepeatString(&quot;<TD> </TD>&quot;,TOPAD)>
<CFOUTPUT>#PADSTR#</CFOUTPUT>
</CFIF>
</TR>
</TABLE>
<!--- This is the navigation bar. --->
<CFOUTPUT>
<!--- Calculate dates to pass back to ViewSchedule.cfm --->
<CFSET PriorDay = 1>
<CFSET PriorMonth = Month(DateAdd(&quot;m&quot;,-1,DisplayDate))>
<CFIF PriorMonth EQ ThisMonth>
<CFSET PriorDay = ThisDay>
</CFIF>
<CFIF PriorMonth EQ 12>
<CFSET PriorYear = Year(DateAdd(&quot;yyyy&quot;,-1,DisplayDate))>
<CFELSE>
<CFSET PriorYear = Year(DisplayDate)>
</CFIF>
<CFSET PriorDate = CreateDate(PriorYear,PriorMonth,PriorDay)>
<CFSET NextDay = 1>
<CFSET NextMonth = Month(DateAdd(&quot;m&quot;,1,DisplayDate))>
<CFIF NextMonth EQ ThisMonth>
<CFSET NextDay = ThisDay>
</CFIF>
<CFIF NextMonth EQ 1>
<CFSET NextYear = Year(DateAdd(&quot;yyyy&quot;,1,DisplayDate))>
<CFELSE>
<CFSET NextYear = Year(DisplayDate)>
</CFIF>
<CFSET NextDate = CreateDate(NextYear,NextMonth,NextDay)>
<!--- Display the navigation bar. --->
<TABLE CLASS=&quot;Reserve&quot; WIDTH=&quot;200&quot; BGCOLOR=&quot;#Application.MediumColor#&quot; BORDER=&quot;1&quot; BORDERCOLOR=&quot;#Application.DarkColor#&quot;>
<TR>
<TD ALIGN=&quot;center&quot;><A HREF=&quot;#PageLink#?DisplayDate=#PriorDate#&quot;><SPAN CLASS=&quot;BigBlack&quot;><<< Prior</SPAN></A></TD>
<TD ALIGN=&quot;center&quot;><A HREF=&quot;#PageLink#?DisplayDate=#NextDate#&quot;><SPAN CLASS=&quot;BigBlack&quot;>Next >>></SPAN></A></TD>
</TR>
</TABLE>
</CFOUTPUT>
Calista :-X
Jedi Knight,
Champion of the Force
 
Hey thanks,

It displays the current month but I can get it to do previous and next.... can you check out my code...

I have changed it slightly...

It's uploaded at

Cheers

Mark ;-)



<!--- Inputs required: DisplayDate (ODBC Date/Time object) --->
<CFSET TodaysDate = Now()>
<CFSET ThisMonth = Month(TodaysDate)>
<CFSET ThisDay = Day(TodaysDate)>
<CFSET DisplayDate = Now()>
<CFSET PageLink = &quot;cal.cfm&quot;>


<CFOUTPUT>
<TABLE WIDTH=&quot;200&quot; CELLPADDING=&quot;3&quot; BORDER=&quot;1&quot;>
<TR BGCOLOR=&quot;##ff9900&quot;>
<TD COLSPAN=&quot;7&quot; ALIGN=&quot;center&quot;>
<B>#MonthAsString(Month(DisplayDate))# #Year(DisplayDate)#</B>
</TD>
</TR>
</CFOUTPUT>
<!--- Now we need to display the weeks of the month. --->
<!--- The logic here is not too complex. We know that every 7 days we need to start a new table row. The only hard part is figuring out how much we need to pad the first and last row. To figure out how much we need to pad, we just figure out what day of the week the first of the month is. if it is wednesday, then we need to pad for sunday,monday, and tuesday. 3 days. --->
<TR>
<CFSET FIRSTOFMONTH=CreateDate(Year(DisplayDate),Month(DisplayDate),1)>
<CFSET TOPAD=DayOfWeek(FIRSTOFMONTH) - 1>
<CFSET PADSTR=RepeatString(&quot;<TD> </TD>&quot;,TOPAD)>
<CFOUTPUT>#PADSTR#</CFOUTPUT>
<CFSET DW=TOPAD>
<CFLOOP INDEX=&quot;X&quot; FROM=&quot;1&quot; TO=&quot;#DaysInMonth(DisplayDate)#&quot;>
<TD ALIGN=&quot;center&quot;><CFOUTPUT><A HREF=&quot;#PageLink#?gigid=#X#&quot;>#X#</A></CFOUTPUT></TD>
<CFSET DW=DW + 1>
<CFIF DW EQ 7>
</TR>
<CFSET DW=0>
<CFIF X LT DaysInMonth(DisplayDate)><TR></CFIF>
</CFIF>
</CFLOOP>
<!---
Now we need to do a pad at the end, just to make our table &quot;proper&quot; we can figure out how much the pad should be by examining DW --->
<CFSET TOPAD=7 - DW>
<CFIF TOPAD LT 7>
<CFSET PADSTR=RepeatString(&quot;<TD> </TD>&quot;,TOPAD)>
<CFOUTPUT>#PADSTR#</CFOUTPUT>
</CFIF>
</TR>
</TABLE>
<!--- This is the navigation bar. --->
<CFOUTPUT>
<!--- Calculate dates to pass back to ViewSchedule.cfm --->
<CFSET PriorDay = 1>
<CFSET PriorMonth = Month(DateAdd(&quot;m&quot;,-1,DisplayDate))>
<CFIF PriorMonth EQ ThisMonth>
<CFSET PriorDay = ThisDay>
</CFIF>
<CFIF PriorMonth EQ 12>
<CFSET PriorYear = Year(DateAdd(&quot;yyyy&quot;,-1,DisplayDate))>
<CFELSE>
<CFSET PriorYear = Year(DisplayDate)>
</CFIF>
<CFSET PriorDate = CreateDate(PriorYear,PriorMonth,PriorDay)>
<CFSET NextDay = 1>
<CFSET NextMonth = Month(DateAdd(&quot;m&quot;,1,DisplayDate))>
<CFIF NextMonth EQ ThisMonth>
<CFSET NextDay = ThisDay>
</CFIF>
<CFIF NextMonth EQ 1>
<CFSET NextYear = Year(DateAdd(&quot;yyyy&quot;,1,DisplayDate))>
<CFELSE>
<CFSET NextYear = Year(DisplayDate)>
</CFIF>
<CFSET NextDate = CreateDate(NextYear,NextMonth,NextDay)>
<!--- Display the navigation bar. --->
<TABLE WIDTH=&quot;200&quot; BORDER=&quot;1&quot;>
<TR>
<TD ALIGN=&quot;center&quot;><A HREF=&quot;cal.cfm?DisplayDate=#PriorDate#&quot;><<< 1Prior</A></TD>
<TD ALIGN=&quot;center&quot;><A HREF=&quot;cal.cfm?DisplayDate=#NextDate#&quot;>Next2 >>></A></TD>
</TR>
</TABLE>
</CFOUTPUT>
 
I checked out your calendar, and it looks OK to me. Were you trying to display more than one month at a time? Is that why your navigation arrow says &quot;Next 2&quot;? Calista :-X
Jedi Knight,
Champion of the Force
 
Oops.... sorry... I was being thick... I fixed it... it now works with previosu and next months!!! ooops ... I forgot I put a url on this site... but thanks for looking...

the reason there is a 2 is 'coz I had a casche problem... and it was so that i new it was the right version...

Now the issue i need to address is the fact that I need to query the database... to find matching dates... only place a hyperlink on dates that match an event in the table... the rest of the dates in that month need to be static...

Can anyone help me? Please...

Cheers

M ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top