我制作了一个PHP事件日历,用户可以在其中添加事件..
现在我要强调有活动的那一天。我已经在te sreenshot上显示了当天的日子:
http://i41.tinypic.com/t0nlti.png
</script>
<style>
.today{
background-color: #00ff00;
}
.event{
background-color: #FF8080;
}
</style>
实际代码:
$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'";
}
}
如你所见,今天的重点很好。
$eventsdate = $month."-".$month."-".$day;
数据库布局:
http://i41.tinypic.com/2luvok4.png
希望有人能帮助我。
答案 0 :(得分:1)
$dateToCompare
采用m / d / y格式,您的数据库日期以y-m-d格式存储。
为简单起见(并假设这些变量未在其他任何地方使用),您可以将所有内容保持为相同的格式:
$todaysDate = date("Y-m-d");
$dateToCompare = $year . '-'.$monthstring. '-' . $daystring;