0

I have made an PHP Event calender where the user can add events..

Now i want to highlight the day where there is an event. I have already highlighted the current day like shown on te sreenshot:

http://i41.tinypic.com/t0nlti.png

</script>
<style>
.today{
background-color: #00ff00;
}
.event{
background-color: #FF8080;
}
</style>

Actual code:

$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' ";
if ($todaysDate == $dateToCompare){
echo "class ='today'";
} 
//here it goes wrong..
else
{
 $sqlCount = "select * from eventcalendar where eventDate='".$dateToCompare."'";
 $noOfEvent = mysql_num_rows(mysql_query($sqlCount));
 if($noOfEvent >= 1){
 echo "class='event'";
 }
}

As you see the highlighting of today goes fine.

$eventsdate = $month."-".$month."-".$day;

DB layout:

http://i41.tinypic.com/2luvok4.png

Hope anyone can help me.

4

1 回答 1

1

$dateToCompare采用 m/d/y 格式,因为您的 db 日期以 ymd 格式存储。

为简单起见(并假设这些变量未在其他任何地方使用),您可以将所有内容保持在相同的格式:

$todaysDate = date("Y-m-d");
$dateToCompare = $year . '-'.$monthstring. '-' . $daystring;
于 2013-10-15T13:05:29.327 回答