我有一个PHP / Mysql日历,它没有从我的数据库加载事件。
我在这里调用我的数据库中的事件:
/* date settings */
$month = (int) ($_GET['month'] ? $_GET['month'] : date('m'));
$year = (int) ($_GET['year'] ? $_GET['year'] : date('Y'));
/* get all events for the given month */
$con = mysql_connect('***************', '******', '*******');
mysql_select_db(dbbmdmi);
$events = array();
$query = "SELECT CaptainLast, ArrDate FROM Teams";
$result = mysql_query($query) or die('cannot get results!');
while($rows = mysql_fetch_assoc($result)) {
$events[$rows['ArrDate']] = $rows;
}
...这里正确输出:
foreach ($events as $data) {
echo "Captain: $data[CaptainLast], Date: $data[ArrDate]<br />\n";
}
...但请不要在此处填写我的日历日:
$event_day = $year.'-'.$month.'-'.$list_day;
if(isset($events[$event_day])) {
foreach($events[$event_day] as $event) {
$calendar.= '<div class="event">'.$event[CaptainLast].'</div>';
}
}
else {
$calendar.= str_repeat('<p> </p>',2);
}
非常感谢任何帮助。
答案 0 :(得分:0)
我能够让它工作,我认为这与日期/时间格式有关,而不是任何事情。
$event_day = date('Y-m-d',strtotime($year.'-'.$month.'-'.$list_day));
foreach($events as $event) {
if ($event[ArrDate] == $event_day) {
$cntry = $event[CountryID];
$calendar.= '</br></br><div class="event" style="background-color:#1' .stringToColorCode($cntry). '">'.$event[CaptainLast]."<div class='teampopup'><table><tbody><tr><u>Team Info:</u></tr></br><tr>Captain: " . $event[CaptainFirst]. " " . $event[CaptainLast] . "</tr></br><tr>Country: " . $event[CountryID]. "</tr></br><tr>Dates: " . date("n/j",strtotime($event[ArrDate])). " - ". date("n/j",strtotime($event[DepDate])). ", " . date("Y",strtotime($event[ArrDate])). "</tr></br><tr>Type: " . $event[Type]. "</tr></tbody></table></div></div>";
}
}