易心博客网->技术文章->博客日历的实现
本文引用地址:http://www.ex123.net/tb.asp?id=42
*****************************************************
原创作者:易心  QQ 343931221
个人网站:www.ex123.net
作品由易心原创,转载请保留此版权信息。
*****************************************************
代码注解:
'******************************************
'日历
'参数 年 月 日
'******************************************
Function show_Calendar(c_year,c_month,c_day)
 dim monthrs,monthsql,theday
 'monthrs是在要显示的月中发表日志的日期
 'monthsql是查询要显示月中发表日志的日期的sql语句
 theday=0 '作为发表日志日期数组的下标
 redim linkdays(0)'发表日志数组
 If c_year=0 Or IsEmpty(c_year) Then'如果参数为空或者为0
 c_year=Year(now)'取当前年
 End If
 If c_month=0 Or IsEmpty(c_month) Then
 c_month=Month(now)
 End If
 If c_day=0 Or IsEmpty(C_day) Then
 c_day=Day(now)
 End If
 If c_month>12 Then'如果月份大于12则
 c_month=1'月份变为下一年的一月
 c_year=c_year+1'年份长一年
 End If
 If c_month<1 Then'如果月份小于1则
 c_month=12'月份变为上年的12月
 c_year=c_year-1'年份减一年
 End if
 monthsql="select * from log where log_postyear="&c_year&" and log_postmonth="&c_month&" order by log_postday asc"'构造查询语句
 Set monthrs=db.execute(monthsql)'执行查询
 Do While Not monthrs.eof'如果记录不为空
 ReDim preserve linkdays(theday) '重定义存放日期的数组linkdays()
 linkdays(theday)=monthrs("log_postday")
 theday=theday+1
 monthrs.movenext
 Loop
Dim Month_Days(12) '每月天数 控制单元格输出
 Month_Days(0)=""
 Month_Days(1)=31
 Month_Days(2)=28
 Month_Days(3)=31
 Month_Days(4)=30
 Month_Days(5)=31
 Month_Days(6)=30
 Month_Days(7)=31
 Month_Days(8)=30
 Month_Days(9)=31
 Month_Days(10)=31
 Month_Days(11)=30
 Month_Days(12)=31
If IsDate("2/29/"&c_year) Then '判断是闰年还是平年
month_days(2)=29
End if
Dim startday
startday=Weekday(c_month&"/1/"&c_year) '判断日期开始单元格
Dim calendarstr
'以下是在页面上输出的内容
calendarstr=calendarstr&"<table width=""98%""  border=""0"" align=""center"">"
calendarstr=calendarstr&"  <tr>"
calendarstr=calendarstr&"    <th colspan=""7""><a href=""index.asp?c_year="&c_year-1&""" title=上一年><</a><a href=""index.asp?c_month="&c_month-1&"&c_year="&c_year&""" title=上一月><</a>"&c_year&"年"&c_month&"月<a href=""index.asp?c_month="&c_month+1&"&c_year="&c_year&""" title=下一月>></a><a href=""index.asp?c_year="&c_year+1&""" title=下一年>></a></th>"
calendarstr=calendarstr&"  </tr>"
calendarstr=calendarstr&"  <tr>"
calendarstr=calendarstr&"    <td width=""14%"">日</td>"
calendarstr=calendarstr&"    <td width=""14%"">一</td>"
calendarstr=calendarstr&"    <td width=""15%"">二</td>"
calendarstr=calendarstr&"    <td width=""15%"">三</td>"
calendarstr=calendarstr&"    <td width=""15%"">四</td>"
calendarstr=calendarstr&"    <td width=""14%"">五</td>"
calendarstr=calendarstr&"    <td width=""13%"">六</td>"
calendarstr=calendarstr&"  </tr>"
  Dim i,m,flag
  For i=1 To 42
  flag=0'如果发表日志的日期数组中包含当前要输出的日期则flag变为1
   If i Mod 7=1 Then
   calendarstr=calendarstr&"<tr>"
   End If
  If i<startday Or (i-startday+1)>month_days(c_month) Then   '如果i小于开始日期或大于本月天数
  calendarstr=calendarstr&"<td>&nbsp;</td>" '输出空内容的单元格
  Else
  For m=0 To theday-1 'for循环用于判断现在输出的日期是不是发表日志日期
           If (i-startday+1)=linkdays(m) Then'如果是且日期小于天数
           calendarstr=calendarstr&"<td><a href=""blogview.asp?c_year="&c_year&"&c_month="&c_month&"&c_day="&i-startday+1&""">"&i-startday+1&"</a></td>"'输出连接
           flag=1
            Exit for '终止循环
            End If
  Next        
  If flag=0 then'如果没有输出代有连接的日期
  calendarstr=calendarstr&"<td>"&i-startday+1&"</td>"'只是输出日期但没有连接
  End If
  End If
  If i Mod 7=0 Then
  calendarstr=calendarstr&"</tr>"
  End if
  Next
  calendarstr=calendarstr&"</table>"
  show_calendar=calendarstr
  End Function

相关日志:博客 日历 
查看回复 回复日志 

copyright©ex123.net 2005冀ICP备05025454号