SitePoint Sponsor

User Tag List

Results 1 to 22 of 22
  1. #1
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with event calendar

    Hi,

    I've made an event calendar (asp/access), it works ok, but it could be faster.

    Code:
    'EventDate = date()
    If Request("navi") <> "" Then
       EventDate = DateValue(Request("navi"))
    Else
       EventDate = date
    End if
    
    CurrentMonth = Month(EventDate)
    mnd = MonthName(CurrentMonth)
    CurrentMonthName = ucase(left(mnd, 1)) & right(mnd, len(mnd)-1)
    CurrentYear = Year(EventDate)
    FirstDayDate = DateSerial(CurrentYear, CurrentMonth, 1)
    FirstDay = WeekDay(FirstDayDate, 0)
    CurrentDay = FirstDayDate
    
    html = 		  "<table class='" & css_class_tbl & "' cellpadding='0' cellspacing='0'>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    html = html & "		<td colspan='7' class='" & css_class_month & "'>" & four_months & "</td>" & vbcrlf
    html = html & "	</tr>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    html = html & "		<td colspan='7' class='" & css_class_month & "'>&nbsp;</td>" & vbcrlf
    html = html & "	</tr>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    html = html & "		<td colspan='7' class='" & css_class_month & "'><a href=""?navi=" & DateAdd("m",-1, EventDate) & """><img src=""img/paging-back.gif"" width=""15"" height=""15"" border=""0""></a> " & CurrentMonthName & ", " & CurrentYear & " <a href=""?navi=" & DateAdd("m",1, EventDate) & """><img src=""img/paging-next.gif"" width=""15"" height=""15"" border=""0""></a></td>" & vbcrlf
    html = html & "	</tr>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(0, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(1, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(2, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(3, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(4, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(5, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(6, user_lang) & "</td>" & vbcrlf
    html = html & "	</tr>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    
    if FirstDay <> 1 then 		
    	html = html & "<td Colspan='" & FirstDay -1 & "' class='" & css_class_blanks & "'>&nbsp;" & vbcrlf
    end if
    
    padding = FirstDay -1
    
    DayCounter = FirstDay
    CorrectMonth = true
    
    do while CorrectMonth = true
    	db_connect 'Sub db_connect i dbfunc.asp
    	SQL_query = "SELECT * FROM arrangement WHERE dato LIKE '" & CurrentDay & "' ORDER by start ASC"
    	'SQL_query = "SELECT * FROM arrangement"
    	db_query(SQL_query) 'function db_query i dbfunc.asp
    
    	day_html = "<table class=""cal_content"" width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">"
    	count_events = 0
    	
    'html events
    	while NOT RS.EOF 
    		'tooltip
    		overlib = "onmouseover=""return overlib('" & timeformat(RS.Fields("start")) & " - " & timeformat(RS.Fields("slutt")) & " " & RS.Fields("overskrift") & "',CENTER,OFFSETY,'40',DELAY,'200',WIDTH,'250');"" onmouseout=""return nd();"""	 
    		if SESSION("user_level") = "admin" then
    			day_html = day_html & "<tr>"
    			day_html = day_html & "<td><a class='" & css_class_links_events & "' href=""edit.asp?cid="& RS.Fields("id") &"&EventDate=" & CurrentDay & """><img src=""img/edit.gif"" width=""10"" height=""10"" border=""0""></a><a class=""" & css_class_links & """ href=""view.asp?cid=" & RS.Fields("id") & "&EventDate=" & CurrentDay & """" & overlib & ">" & RS.Fields("overskrift") & "</a></td>"
    			day_html = day_html & "</tr>"
    		else
    			day_html = day_html & "<tr>"
    			day_html = day_html & "<td><a class='" & css_class_links_events & "' href=""view.asp?cid="& RS.Fields("id") &"&EventDate=" & CurrentDay & """" & overlib & ">" & RS.Fields("overskrift") & "</a></td>"
    			day_html = day_html & "</tr>"
    		end if
    		RS.Movenext
    		count_events = count_events + 1
    	wend
    	'event padding
    	if count_events < 4 then
    		while count_events < 4
    			day_html = day_html & "<tr>"
    			day_html = day_html & "<td>&nbsp;</td>"
    			day_html = day_html & "</tr>"
    			count_events = count_events + 1
    		wend
    	end if
    	day_html = day_html & "</table>"
    'html events
    
    	if SESSION("user_level") = "admin" then
    		if CurrentDay = EventDate then
    		   html = html & "<td class='" & css_class_today & "'>" & "<a class='" & css_class_links & "' href='" & cal_action_url & "?EventDate=" & CurrentDay & "'>" & Day(CurrentDay) & "</a>" & day_html & "</td>" & vbcrlf
    		else
    		   html = html & "<td class='" & css_class_days & "'>" & "<a class='" & css_class_links & "' href='" & cal_action_url & "?EventDate=" & CurrentDay & "'>" & Day(CurrentDay) & "</a>" & day_html & "</td>" & vbcrlf
    		end if
    	else
    		if CurrentDay = EventDate then
    		   html = html & "<td class='" & css_class_today & "'>" & Day(CurrentDay) & day_html & "</td>" & vbcrlf
    		else
    		   html = html & "<td class='" & css_class_days & "'>" & Day(CurrentDay) & day_html & "</td>" & vbcrlf
    		end if
    	end if
    	
    	DayCounter = DayCounter + 1
    	if DayCounter > 7 then
    	   DayCounter = 1
    	   html = html & "</tr>" & vbcrlf & "<tr>" & vbcrlf
    	end if
    	
    	CurrentDay = DateAdd("d", 1, CurrentDay)
    	
    	if Month(CurrentDay) <> CurrentMonth then
    	   CorrectMonth = false
    	end if
    loop
    
    if DayCounter <> 1 then
       html = html & "<td Colspan='" & 8-DayCounter & "' class='" & css_class_blanks & "'>&nbsp;</td>" & vbcrlf
    end if
    html = html & "</tr>" & vbcrlf
    html = html & "</table>" & vbcrlf
    
    response.write html
    db_kill
    what i would like to do is to put my recordset in an array before the calendar loop begins, and then loop through the array

    as you can se from my code, i run a query for each day, and that slows thing down

    Code:
    do while CorrectMonth = true
      db_connect 'Sub db_connect i dbfunc.asp
      SQL_query = "SELECT * FROM arrangement WHERE dato LIKE '" & CurrentDay & "' ORDER by start ASC"
      db_query(SQL_query) 'function db_query i dbfunc.asp
    any help is highly apprechiated


    Chris
    Last edited by silverviper; Oct 6, 2006 at 12:25.

  2. #2
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks pretty easy to change

    - calculate first/last days of month:
    Code:
    FirstDayDate = DateSerial(CurrentYear, CurrentMonth, 1)
    LastDayDate = DateAdd("d", -1, DateSerial(CurrentYear, CurrentMonth + 1, 1))
    - change query to get all records for the month
    - the query needs to be moved outside the main (day) loop
    Code:
    SQL_query = "SELECT * FROM arrangement WHERE dato >= '" & FirstDayDate & "' AND dato <= '" & LastDayDate & "' ORDER BY dato ASC, start ASC"
    - for the inner loop (while NOT RS.EOF) change it to
    Code:
    while RS.Fields("dato") = DayCounter And NOT RS.EOF
    That should work, might be a couple of other things to fix but I think it will get you started. If you're only running the one query no need to use getrows really.

  4. #4
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi thx guys

    almost there.



    SELECT * FROM arrangement WHERE dato >= '01.09.2006' AND dato <= '30.09.2006' ORDER BY dato ASC, start ASC

    im getting this sql error

    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

    Chris

  5. #5
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Access requires # sign around dates.
    Code:
    SELECT * FROM arrangement WHERE dato >= #01.09.2006# AND dato <= #30.09.2006# ORDER BY dato ASC, start ASC
    assuming dato is a date field. if it's text, then you can't use >= <=.

  6. #6
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, thx for the reply

    dato is a datefield shortdate dd.mm.yyyy

    SELECT * FROM arrangement WHERE dato >= #01.09.2006# AND dato <= #30.09.2006# ORDER BY dato ASC, start ASC

    now i get this syntax error

    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression 'dato >= #01.09.2006# AND dato <= #30.09.2006#'.

  7. #7
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    access probably doesn't understand the dot as the seperator (but i'm not sure about this). does it work if using a slash instead of the dot? ie: 01/09/2006. the other thing is to make sure that Access is understanding dd/mm/yyyy. if i remember, Access is by default mm/dd/yyyy.

  8. #8
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, thx

    SELECT * FROM arrangement WHERE dato >= #09/01/2006# AND dato <= #09/30/2006# ORDER BY dato ASC, start ASC

    SELECT * FROM arrangement WHERE dato >= #01/09/2006# AND dato <= #30/09/2006# ORDER BY dato ASC, start ASC

    i get no error with these, but they do not return any records

    Chris

  9. #9
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I always use the yyyy-mm-dd format so there is never any ambiguity.

    Try
    SELECT * FROM arrangement WHERE dato >= #2006-09-01# AND dato <= #2006-09-30# ORDER BY dato ASC, start ASC

  10. #10
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, thx

    SELECT * FROM arrangement WHERE dato >= #2006-09-01# AND dato <= #2006-09-30# ORDER BY dato ASC, start ASC

    i get no error with this, but it does not return any records

  11. #11
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    the sql string may not be the only problem

    SQL_query = "SELECT * FROM arrangement"

    this does not return any records either

  12. #12
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are there records in there? obvious question i know, but...

  13. #13
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    yes there are about 25 of records from 01.09.2006 (sep 1 2006) to 30.09.2006 (sep 30 2006)

    i think there is a problem with the inner loop

    Chris

  14. #14
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    while NOT RS.EOF
    if RS is dimmed inside one of your data subs, it isn't available outside of that sub (or at least the data it holds). I don't see it dimmed on your code in the first post.

  15. #15
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post your updated code please

  16. #16
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function dateformat(str)
    	str = Replace(str,".","/")
    	dateformat = str
    end function
    
    'EventDate = date()
    If Request("navi") <> "" Then
       EventDate = DateValue(Request("navi"))
    Else
       EventDate = date
    End if
    
    CurrentMonth = Month(EventDate)
    mnd = MonthName(CurrentMonth)
    CurrentMonthName = ucase(left(mnd, 1)) & right(mnd, len(mnd)-1)
    CurrentYear = Year(EventDate)
    FirstDayDate = DateSerial(CurrentYear, CurrentMonth, 1)
    LastDayDate = DateAdd("d", -1, DateSerial(CurrentYear, CurrentMonth + 1, 1))
    FirstDay = WeekDay(FirstDayDate, 0)
    CurrentDay = FirstDayDate
    
    html = 		  "<table class='" & css_class_tbl & "' cellpadding='0' cellspacing='0'>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    html = html & "		<td colspan='7' class='" & css_class_month & "'>" & four_months & "</td>" & vbcrlf
    html = html & "	</tr>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    html = html & "		<td colspan='7' class='" & css_class_month & "'>&nbsp;</td>" & vbcrlf
    html = html & "	</tr>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    html = html & "		<td colspan='7' class='" & css_class_month & "'><a href=""?navi=" & DateAdd("m",-1, EventDate) & """><img src=""img/paging-back.gif"" width=""15"" height=""15"" border=""0""></a> " & CurrentMonthName & ", " & CurrentYear & " <a href=""?navi=" & DateAdd("m",1, EventDate) & """><img src=""img/paging-next.gif"" width=""15"" height=""15"" border=""0""></a></td>" & vbcrlf
    html = html & "	</tr>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(0, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(1, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(2, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(3, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(4, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(5, user_lang) & "</td>" & vbcrlf
    html = html & "		<td class='" & css_class_daynames & "'>" & day_names(6, user_lang) & "</td>" & vbcrlf
    html = html & "	</tr>" & vbcrlf
    html = html & "	<tr>" & vbcrlf
    
    if FirstDay <> 1 then 		
    	html = html & "<td Colspan='" & FirstDay -1 & "' class='" & css_class_blanks & "'>&nbsp;" & vbcrlf
    end if
    
    padding = FirstDay -1
    
    DayCounter = FirstDay
    
    CorrectMonth = true
    	db_connect 'Sub db_connect i dbfunc.asp
    	'SQL_query = "SELECT * FROM arrangement WHERE dato LIKE '" & CurrentDay & "' ORDER by start ASC"
    	'SQL_query = "SELECT * FROM arrangement"
    	'SQL_query = "SELECT * FROM arrangement"
    	SQL_query = "SELECT * FROM arrangement WHERE dato >= #" & dateformat(FirstDayDate) & "# AND dato <= #" & dateformat(LastDayDate) & "# ORDER BY dato ASC, start ASC"
    	db_query(SQL_query) 'function db_query i dbfunc.asp
    
    do while CorrectMonth = true
    
    	day_html = "<table class=""cal_content"" width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">" & vbcrlf
    	count_events = 0
    	
    'html events
    	while RS.Fields("dato") = DayCounter And NOT RS.EOF
    		'tooltip
    		overlib = "onmouseover=""return overlib('" & timeformat(RS.Fields("start")) & " - " & timeformat(RS.Fields("slutt")) & " " & RS.Fields("overskrift") & "',CENTER,OFFSETY,'40',DELAY,'200',WIDTH,'250');"" onmouseout=""return nd();"""	 
    		if SESSION("user_level") = "admin" then
    			day_html = day_html & "<tr>"& vbcrlf
    			day_html = day_html & "<td><a class='" & css_class_links_events & "' href=""edit.asp?cid="& RS.Fields("id") &"&EventDate=" & CurrentDay & """><img src=""img/edit.gif"" width=""10"" height=""10"" border=""0""></a><a class=""" & css_class_links & """ href=""view.asp?cid=" & RS.Fields("id") & "&EventDate=" & CurrentDay & """" & overlib & ">" & RS.Fields("overskrift") & "</a></td>"& vbcrlf
    			day_html = day_html & "</tr>"& vbcrlf
    		else
    			day_html = day_html & "<tr>"& vbcrlf
    			day_html = day_html & "<td><a class='" & css_class_links_events & "' href=""view.asp?cid="& RS.Fields("id") &"&EventDate=" & CurrentDay & """" & overlib & ">" & RS.Fields("overskrift") & "</a></td>"& vbcrlf
    			day_html = day_html & "</tr>"& vbcrlf
    		end if
    		count_events = count_events + 1
    	RS.Movenext
    	wend
    	
    	'event padding
    	if count_events < 4 then
    		while count_events < 4
    			day_html = day_html & "<tr>"& vbcrlf
    			day_html = day_html & "<td>&nbsp;</td>"& vbcrlf
    			day_html = day_html & "</tr>"& vbcrlf
    			count_events = count_events + 1
    		wend
    	end if
    	day_html = day_html & "</table>"& vbcrlf
    'html events
    
    	if SESSION("user_level") = "admin" then
    	if CurrentDay = EventDate then
    		   html = html & "<td class='" & css_class_today & "'>" & "<a class='" & css_class_links & "' href='" & cal_action_url & "?EventDate=" & CurrentDay & "'>" & Day(CurrentDay) & "</a>" & day_html & "</td>" & vbcrlf
    		else
    		   html = html & "<td class='" & css_class_days & "'>" & "<a class='" & css_class_links & "' href='" & cal_action_url & "?EventDate=" & CurrentDay & "'>" & Day(CurrentDay) & "</a>" & day_html & "</td>" & vbcrlf
    		end if
    	else
    		if CurrentDay = EventDate then
    		   html = html & "<td class='" & css_class_today & "'>" & Day(CurrentDay) & day_html & "</td>" & vbcrlf
    		else
    		   html = html & "<td class='" & css_class_days & "'>" & Day(CurrentDay) & day_html & "</td>" & vbcrlf
    		end if
    	end if
    	
    	DayCounter = DayCounter + 1
    	if DayCounter > 7 then
    	   DayCounter = 1
    	   html = html & "</tr>" & vbcrlf & "<tr>" & vbcrlf
    	end if
    	
    	CurrentDay = DateAdd("d", 1, CurrentDay)
    	
    	if Month(CurrentDay) <> CurrentMonth then
    	   CorrectMonth = false
    	end if
    loop
    
    if DayCounter <> 1 then
       html = html & "<td Colspan='" & 8-DayCounter & "' class='" & css_class_blanks & "'>&nbsp;</td>" & vbcrlf
    end if
    html = html & "</tr>" & vbcrlf
    html = html & "</table>" & vbcrlf
    
    response.write html
    db_kill
    edit: while RS.Fields("dato") = DayCounter And NOT RS.EOF

    DayCounter counts the days in a week 1-7, so it might not fit in this loop

    Chris
    Last edited by silverviper; Sep 29, 2006 at 01:42.

  17. #17
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone got a fix for this calendar?

    thx

    Chris

  18. #18
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    You're right - the problem's with the inner loop. I've copied your code and will be looking at it for a couple minutes...
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  19. #19
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by DaveMaxwell
    You're right - the problem's with the inner loop. I've copied your code and will be looking at it for a couple minutes...
    OK, try this. I've tried to comment heavily so you can see where I'm going with it.

    Disclaimer: This has not been tested, only roughed out, so there may be (ok - probably are) typos, so test thorougly.

    Code:
    <%
    function dateformat(str)
    	str = Replace(str,".","/")
    	dateformat = str
    end function
    
    'EventDate = date()
    If Request("navi") <> "" Then
       EventDate = DateValue(Request("navi"))
    Else
       EventDate = date
    End if
    
    CurrentMonth = Month(EventDate)
    mnd = MonthName(CurrentMonth)
    CurrentMonthName = ucase(left(mnd, 1)) & right(mnd, len(mnd)-1)
    CurrentYear = Year(EventDate)
    FirstDayDate = DateSerial(CurrentYear, CurrentMonth, 1)
    LastDayDate = DateAdd("d", -1, DateSerial(CurrentYear, CurrentMonth + 1, 1))
    FirstDay = WeekDay(FirstDayDate, 0)
    CurrentDay = FirstDayDate
    
    padding = FirstDay -1
    
    db_connect 'Sub db_connect i dbfunc.asp
    SQL_query = "SELECT id, dato, start, slutt, overskrift" & _
    			"  FROM arrangement " & _
    			" WHERE dato >= #" & dateformat(FirstDayDate) & "#" & _
    			"   AND dato <= #" & dateformat(LastDayDate) & "#" & _
    			" ORDER BY dato ASC, start ASC"
    		
    db_query(SQL_query) 'function db_query i dbfunc.asp
    
    If rs.EOF And rs.BOF Then
    	Response.Write "No events found for this month"
    	rs.close	:	Set rs = nothing
    Else
    	' Records found, so move it into a array for faster processing
    	arrRecSet = rs.getrows(-1)	:	recCount = UBound(arrRecSet, 2)
    	rs.close	:	Set rs = nothing
    	' Start to build the HTML for the month...
    	html = 		  "<table class='" & css_class_tbl & "' cellpadding='0' cellspacing='0'>" & vbcrlf
    	html = html & "	<tr>" & vbcrlf
    	html = html & "		<td colspan='7' class='" & css_class_month & "'>" & four_months & "</td>" & vbcrlf
    	html = html & "	</tr>" & vbcrlf
    	html = html & "	<tr>" & vbcrlf
    	html = html & "		<td colspan='7' class='" & css_class_month & "'>&nbsp;</td>" & vbcrlf
    	html = html & "	</tr>" & vbcrlf
    	html = html & "	<tr>" & vbcrlf
    	html = html & "		<td colspan='7' class='" & css_class_month & "'><a href=""?navi=" & DateAdd("m",-1, EventDate) & """><img src=""img/paging-back.gif"" width=""15"" height=""15"" border=""0""></a> " & CurrentMonthName & ", " & CurrentYear & " <a href=""?navi=" & DateAdd("m",1, EventDate) & """><img src=""img/paging-next.gif"" width=""15"" height=""15"" border=""0""></a></td>" & vbcrlf
    	html = html & "	</tr>" & vbcrlf
    	html = html & "	<tr>" & vbcrlf
    	html = html & "		<td class='" & css_class_daynames & "'>" & day_names(0, user_lang) & "</td>" & vbcrlf
    	html = html & "		<td class='" & css_class_daynames & "'>" & day_names(1, user_lang) & "</td>" & vbcrlf
    	html = html & "		<td class='" & css_class_daynames & "'>" & day_names(2, user_lang) & "</td>" & vbcrlf
    	html = html & "		<td class='" & css_class_daynames & "'>" & day_names(3, user_lang) & "</td>" & vbcrlf
    	html = html & "		<td class='" & css_class_daynames & "'>" & day_names(4, user_lang) & "</td>" & vbcrlf
    	html = html & "		<td class='" & css_class_daynames & "'>" & day_names(5, user_lang) & "</td>" & vbcrlf
    	html = html & "		<td class='" & css_class_daynames & "'>" & day_names(6, user_lang) & "</td>" & vbcrlf
    	html = html & "	</tr>" & vbcrlf
    	html = html & "	<tr>" & vbcrlf
    	if FirstDay <> 1 then 		
    		html = html & "<td Colspan='" & FirstDay -1 & "' class='" & css_class_blanks & "'>&nbsp;" & vbcrlf
    		WeekLoop = FirstDay
    	end if
    	LastEventChecked = 0
    	For i = 1 To DatePart("d", LastDayDate)
    		html = html & "	<td>"
    		LoopDay = CDate(CurrentMonth & "/" & i & CurrentYear)
    		blnFound = False
    		EventCount = 0
    		For x = LastEventChecked To recCount
    			' Move the array elements into fields to aid in readability of the code...
    			rsID = arrRecSet(0, x)			:	rsdato = arrRecSet(1, x)
    			rsStart = arrRecSet(2, x)		:	rsSlutt = arrRecSet(3, x)
    			rsOverskrift = arrRecSet(4, x)
    			DateDifference = DateDiff("d", LoopDay, CDate(rsdato)
    			If DateDifference = 0 Then
    				' Event falls onto this day, so put it in the table cell
    				blnFound = True
    				overlib = "onmouseover=""return overlib('" & timeformat(rsStart) & " - " & timeformat(rsSlutt) & " " & rsOverskrift & "',CENTER,OFFSETY,'40',DELAY,'200',WIDTH,'250');"" onmouseout=""return nd();"""
    				' Create the event table...
    				If EventCount = 0 Then day_html = "		<table class=""cal_content"">" & vbcrlf
    				day_html = day_html & "			<tr>"& vbcrlf
    				day_html = day_html & "					<td>"
    				If session("user_level") = "admin" Then
    					day_html = day_html & "<a class='" & css_class_links_events & "' href=""edit.asp?cid="& rsID &"&EventDate=" & LoopDay & """><img src=""img/edit.gif"" width=""10"" height=""10"" border=""0""></a>"
    				End If
    				day_html = day_html & "<a class=""" & css_class_links & """ href=""view.asp?cid=" & rsID & "&EventDate=" & LoopDay & """" & overlib & ">" & rsOverskrift & "</a></td>"& vbcrlf
    				day_html = day_html & "</tr>"& vbcrlf
    				EventCount = EventCount + 1
    			ElseIf DateDifference > 0 Then
    				' Event Date > month date, so stop checking, but setup look to allowe for fewer cycle checks...
    				LastEventChecked = x		' 
    				x = recCount
    			End If
    		Next
    		If blnFound Then
    			' For a consistent table element size???
    			while count_events < 4
    				day_html = day_html & "<tr><td>&nbsp;</td></tr>"& vbcrlf
    				count_events = count_events + 1
    			Wend
    			html = html & day_html & vbCrlf & "		</table>" & vbCrLf
    		Else
    			html = html & "&nbsp;" & vbCrLf
    		End If
    		WeekLoop = WeekLoop + 1
    		If WeekLoop > 7 Then
    			' End of the week....
    			html = html & "<tr>" & vbCrLf
    			If DateDiff("d", LoopDay, LastDayDate) < 0 Then
    				' Not at the end of the month...
    				html = html & "<tr>" & vbCrLf
    			End If
    			WeekLoop = 1
    		End If
    	Next
    	html = html & "</table>"
    	response.write html
    End if
    db_kill
    %>
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  20. #20
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See if this makes a difference:
    while CDate(RS.Fields("dato")) = CDate(DayCounter) And NOT RS.EOF

    If that doesn't help, put this debug before that while:
    Response.Write "dato=" & RS.Fields("dato") & ", Daycounter=" & Daycounter

    to see if the two fields are the same or if international date bug is causing the month/day parts to be switched.

    PS - I hate how dates are handled in ASP and its associated databases....if you have ASP on one server in one language and eg SQLServer on another server in another language, they are different. I've given up and use VARCHAR fields in my database to deal with dates which I write out like
    "2006-01-01 00:00:00"

  21. #21
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by jimfraser
    PS - I hate how dates are handled in ASP and its associated databases....if you have ASP on one server in one language and eg SQLServer on another server in another language, they are different. I've given up and use VARCHAR fields in my database to deal with dates which I write out like
    "2006-01-01 00:00:00"
    It's not asp - it's the databases/ODBC drivers. You'd have the same issues working with any database platform in any other language.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  22. #22
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx m8

    I'm testing the modified code

    Chris


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •