Reputation: 55
here is the screenshoot of my result I am trying to make a calander have some problem with the code.The code where error is generatring is tablerow.php according to me I have put comment where I think the error is. I am trying to change the current day background colour but instead of changing the colour of specific cell the whole month background colour is changed so for whole month of February the colour is green.
calander.php
<html>
<?php include 'dbconnect.php' ?>
<head>Event Calander</head>
<body>
<script>
function goLastMonth(month, year){
if(month == 1) {
--year;
month = 13;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+(month-1)+"&year="+year;
}
function goNextMonth(month, year){
if(month == 12) {
++year;
month = 0;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+(month+1)+"&year="+year;
}
</script>
<style>
.today{
background-color: #00ff00;
}
.event{
background-color: #FF8080;
}
</style>
<table border='0'>
<tr>
<td width='50px' colspan='7' align="center">
<?php include 'tableheader.php' ?>
<?php include 'addingData.php' ?>
<?php echo $monthName.", ".$year; ?></td>
</tr>
<tr>
<td width='50px'>Sun</td>
<td width='50px'>Mon</td>
<td width='50px'>Tue</td>
<td width='50px'>Wed</td>
<td width='50px'>Thu</td>
<td width='50px'>Fri</td>
<td width='50px'>Sat</td>
</tr>
<?php include 'tablerow.php' ?>
</table>
<table >
<tr>
<td ><input style='width:50px;' type='button' value='<'name='previousbutton' onclick ="goLastMonth(<?php echo $month.",".$year?>)"></td>
<td width='50px'></td>
<td width='50px'></td>
<td width='50px'></td>
<td width='50px'></td>
<td width='50px'></td>
<td width='50px'><input style='width:50px;' type='button' value='>'name='nextbutton' onclick ="goNextMonth(<?php echo $month.",".$year?>)"></td>
</tr>
</table>
<?php include 'schedule.php' ?>
</body>
</html>
tablerow.php(this where i change the colour for the current day)
<?php
echo "<tr>";
$first_day = mktime(0,0,0,$month, 1, $year) ;
$name_of_day = date('w', $first_day) ; //get the day of the weeek
//caluting blank days for the month for diaplay
switch($name_of_day){
case "0": $blank = 0;
break;
case "1": $blank = 1;
break;
case "2": $blank = 2;
break;
case "3": $blank = 3;
break;
case "4": $blank = 4;
break;
case "5": $blank = 5;
break;
case "6": $blank = 6;
break;
}
$total_days = cal_days_in_month(0, $month, $year) ;
$day_count = 1;
while ( $blank > 0 ) {
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}
$day_num = 1;
while ( $day_num <= $total_days )
{
$todaysDate = date("n/j/Y");
$dateToCompare = $month. '/' . $day. '/' . $year;
echo "<td align='center' ";
//this is where i am comparing two dates but it is giving error
//every day of the current month is turnin green
if ($todaysDate == $dateToCompare)
{
echo "class ='today'";
}
echo "> <a href='".$_SERVER['PHP_SELF']."?month=".$month."&day=".$day_num."&year=".$year."&v=true'>".$day_num."</a></td>";
$day_num++;
$day_count++;
//Make sure we start a new row every week
if ($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}
while ( $day_count >1 && $day_count <=7 )
{
echo "<td> </td>";
$day_count++;
}
echo "</tr>"
?>
Upvotes: 1
Views: 406
Reputation: 2344
Try changing this:
$dateToCompare = $month. '/' . $day. '/' . $year;
into this:
$dateToCompare = $month. '/' . $day_num. '/' . $year;
Upvotes: 1