php日历补全上下月

发布时间:2014-05-16 22:23:15 阅读:1327次

转:http://www.nowamagic.net/php/php_Calendar.php

getCalendar.js


function getCalendarByMonth(value){
	$.ajax({
		"type":"post",
		cache: false,
		url: "index.php?c=index&m=showCalendar&fresh="+Math.random(),
		async: false,
		data:{"date":value,"url":1},
		success: function(str){
			$("#calendar").html(str);
		}
	});
}

        function showCalendar(){
                $url=$this->post("url");
                $date = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d');
                $date = getdate(strtotime($date));
                #print_r($date);
                $end = getdate(mktime(0, 0, 0, $date['mon'] + 1, 1, $date['year']) - 1);
                $start = getdate(mktime(0, 0, 0, $date['mon'], 1, $date['year']));
                $pre = date('Y-m-d', $start[0] - 1);
                $next = date('Y-m-d', $end[0] + 86400);
                $html = '<table width="100%" border="1" cellspacing="0" bordercolor="#999999" align="center" style="line-height:24px;font-family:Verdana,宋体; font-size: 16px;color:#ffffff;">';
                $html .= '<tr height=30 align=center>';
                #$html .= '<td><a href="' . $PHP_SELF . '?date=' . $pre . '">-</a></td>';
                $html .= '<td><a href="javascript:" onclick="getCalendarByMonth(\''.$pre.'\');"><img src=images/larrow.png border=0></a></td>';
                $html .= '<td colspan="5" align=center>'.$date['year'].'年'.$date['mon'].'月</td>';
                #$html .= '<td><a href="' . $PHP_SELF . '?date=' . $next . '">+</a></td>';
                $html .= '<td><a href="javascript:" onclick="getCalendarByMonth(\''.$next.'\');"><img src=images/rarrow.png border=0></a></td>';
                $html .= '</tr><tr height=30 align=center><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>';
                $arr_tpl = array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '');
                $date_arr = array();
                $j = 0;
                for ($i = 0; $i < $end['mday']; $i++) {  
                    if (!isset($date_arr[$j])) {  
                        $date_arr[$j] = $arr_tpl;  
                    }  
                    $date_arr[$j][($i+$start['wday'])%7] = $i+1;  
                    if ($date_arr[$j][6]) {  
                        $j++;  
                    }  
                }  
                $premon=date("m",strtotime($pre));
                $preyear=date("Y",strtotime($pre));
                $preend = getdate(mktime(0, 0, 0, $premon + 1, 1, $preyear) - 1);  
                $preday=$preend["mday"];
                $now=$date["mon"];
                if($now==3){
                        $height=36;
                }else{
                        $height=43;
                }       
                foreach ($date_arr as $value) {  
                    $html .= '<tr align=center height='.$height.'>';  
                    foreach ($value as $v) {  
                        if ($v) {  
                            if ($v == $date['mday']) {  
                                $html .= '<td bgcolor=#000000><b>' . $v . '</b></td>';  
                            } else {  
                                $html .= '<td '.$style.'>' . $v . '</td>';  
                            }  
                            $old=$v;
                        } else {  
                                if($old>0){
                                        $o=$o+1;
                                        $html .= '<td> '.$o.'</td>';
                                }else{
                                        $sum=0;
                                        foreach($date_arr[0] as $key=>$value){
                                                if($value==""){
                                                        $sum=$sum+1;
                                                }
                                        }
                                        $n=$n+1;
                                        $new=$preday-$sum+$n;
                                        $html .= '<td> '.$new.'</td>';
                                }
                        }
                    }
                    $html .= '</tr>';
                }
                $html .= '</table>';
                if($url==1){
                        echo $html;
                }else{
                        return $html;


                }
          

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:php日历补全上下月 出自老鄢博客 | 欢迎分享