0
在這個日曆在PHP中,我試圖根據一週中的月份和日期更改CSS。我需要做一個函數來分隔已經過去的日子和星期六和星期天,並設置類「cal_dayblock」和其餘日子還沒有通過,下一個月他們在課堂cal_dayPHP日曆IF日期與日期
已經嘗試幾件事情和我沒有收到,請幫我在這IF語句
<?php
$months = date("m");
$years = date("Y");
$day_count = cal_days_in_month(CAL_GREGORIAN, $months, $years);
for($i=1; $i<= $day_count; $i++) {
$date = $months.'/'.$i.'/'.$years;
if($i >= date('d') && $months >= date('m')) {
echo '<div class="cal_day">';
echo '<div class="day_heading">' . $i . '</div>';}
else {
echo '<div class="cal_dayblock">';
echo '<div class="day_heading">' . $i . '</div>';
}
echo '</div>';
}
?>
編輯:
<script language="javascript" type="text/javascript">
function initialCalendar() {
var hr = new XMLHttpRequest();
var url = "calendar_start.php";
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var year = currentTime.getFullYear();
showmonth = month;
showyear = year;
var vars = "showmonth="+showmonth+"showyear="+showyear;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("showCalendar").innerHTML = return_data;
}
}
hr.send(vars);
document.getElementById("showCalendar").innerHTML = "Carregando...";
}
和PHP
$showmonth = $_POST['showmonth'];
$showyear = $_POST['showyear'];
$showmonth = preg_replace('#[^0-9/]#i', '', $showmonth);
$showyear = preg_replace('#[^0-9/]#i', '', $showyear);
得到錯誤becouse,可以幫助我解決它?請
太好了!但如果我的月和年變量從javascript date()發佈到php ..我編輯了代碼 – Frank021
用'$ showyear'和'$ showmonth'替換'$ current_year'和'$ current_month' - 假設你的AJAX工作正常。 –
非常感謝 – Frank021