Hi All
I have been using a PHP calendar on my site since last year, all fine except today I noticed if i click next month it skips feb and goes to march, I moved through till next jan and the same thing
happend again. Any help would be great as I’m lost as to why its doing it and its causing big problems!!
Head Code:
<script>
<!--
function goLastMonth(month, year){
if(month == 1) {
--year;
month = 13;
}
--month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if(monthlength <=1){
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year+"&x=true&locationID=<? echo $locationID;?>&staffID=<? echo $staffID;?>&clientID=<? echo $clientID;?>";
}
function goNextMonth(month, year){
if(month == 12) {
++year;
month = 0;
}
++month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if(monthlength <=1){
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year+"&x=true&locationID=<? echo $locationID;?>&staffID=<? echo $staffID;?>&clientID=<? echo $clientID;?>";
}
//-->
</script>
Body Code:
// build up mini calender
if (isset($_GET['day'])){
$day = $_GET['day'];
} else {
$day = date("j");
}
if(isset($_GET['month'])){
$month = $_GET['month'];
} else {
$month = date("n");
}
if(isset($_GET['year'])){
$year = $_GET['year'];
}else{
$year = date("Y");
}
$currentTimeStamp = strtotime( "$day-$month-$year");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
?>
</p><table width="500" border="1" align="center" cellpadding="5" cellspacing="0">
<tr><td width="479">
<table border='1' align="center" cellpadding="3" cellspacing="0" bordercolor="#000000">
<tr>
<td bordercolor="#000000"><input style='width:50px;' type='button' value='<'name='previousbutton' onclick ="goLastMonth(<?php echo $month.",".$year?>)"></td>
<td colspan='5' span class='grey14'><?php echo $monthName.", ".$year; ?></span></td>
<td><input style='width:50px;' type='button' value='>'name='nextbutton' onclick ="goNextMonth(<?php echo $month.",".$year?>)"></td>
</tr>
<tr bgcolor='#25B8DA' span class='create_slots_header' align='center'>
<td width='25px' bgcolor="#F6851F" class="style1">Mon</td>
<td width='25px' bgcolor="#F6851F">Tue</td>
<td width='25px' bgcolor="#F6851F">Wed</td>
<td width='25px' bgcolor="#F6851F">Thu</td>
<td width='25px' bgcolor="#F6851F">Fri</td>
<td width='25px' bgcolor="#F6851F">Sat</td>
<td width='25px' bgcolor="#F6851F">Sun</td>
</tr>
<?php
echo "<tr>";
for($i = 1; $i < $numDays+1; $i++, $counter++)
{
$timeStamp = strtotime("$year-$month-$i");
if($i == 1)
{
$firstDay = date("w", $timeStamp);
if($firstDay==0)
{
for($j = 1; $j < 7; $j++, $counter++)
{
echo "<td bgcolor='#E5E5E5'> </td>";
}
}
else
{
for($j = 1; $j < $firstDay; $j++, $counter++)
{
echo "<td bgcolor='#E5E5E5'> </td>";
}
}
}
if($counter % 7 == 0)
{
echo"</tr><tr>";
}
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength = strlen($daystring);
if($monthlength <= 1){
$monthstring = "0".$monthstring;
}
if($daylength <=1){
$daystring = "0".$daystring;
}
$todaysDate = date("m/d/Y");
$dateToCompare = $monthstring. '/' . $daystring. '/' . $year;
echo "<td align='center' ";
$queryDate = "$year-$monthstring-$daystring";
$todaysDateCheck = time();
$todaysDateCheck = date('Y-m-d',$todaysDateCheck);
$query = "SELECT recuringID FROM tblServicesGroups WHERE date='$queryDate' AND date>='$todaysDateCheck' AND clientID='$clientID'";
if(!$row = mysql_fetch_array($result))
{
if ($todaysDate == $dateToCompare)
{
echo "class ='today'";
}
echo "><a href='".$_SERVER['PHP_SELF']."?clientID=".$clientID."&locationID=".$locationID."&month=".$monthstring."&day=".$daystring."&year=".$year."&v=true'>".$i."</a></td>";
}
else
{
echo "class = 'event'";
echo "><a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&v=true'>".$i."</a></td>";
}
}
echo "</tr>";
?>
</table>