[英]How to put events in a weekly calendar
Hi i'm making a weekly calendar with php and I wanna put events in the calendar like this example , but I don't know how to echo the events in the calendar at the correct part of the day. 嗨,我正在用php制作每周日历,我想像下面的示例一样在日历中放置事件,但是我不知道如何在一天的正确时间回显日历中的事件。
This is the code I use to echo the calendar : 这是我用来回显日历的代码:
<?php
$dt = new DateTime;
if (isset($_GET['year']) && isset($_GET['week'])) {
$dt->setISODate($_GET['year'], $_GET['week']);
}else{
$dt->setISODate($dt->format('o'), $dt->format('W'));
}
$year = $dt->format('o');
$week = $dt->format('W');
?>
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week-1).'&year='.$year; ?>">Vorige week</a>
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week+1).'&year='.$year; ?>">Volgende week</a>
<?php
$getDatum = $conn->prepare("
SELECT DISTINCT D.DocentID, CONCAT(D.Voornaam, ' ', D.Achternaam) AS Docentnaam, D.Telefoonnummer, D.Mobiel, D.Email, CO.DatumBegin, CO.DatumEind, O.Onderdeelnaam
FROM docenten D
INNER JOIN psentity PE ON D.DocentID = PE.psid
INNER JOIN docentonderdelen DO ON D.DocentID = DO.DocentID
INNER JOIN cursusonderdelen CO ON DO.OnderdeelID = CO.OnderdeelID
RIGHT JOIN onderdelen O ON CO.OnderdeelID = O.OnderdeelID
WHERE O.OnderdeelID = 6
AND CO.DatumBegin AND CO.DatumEind BETWEEN '2018-12-10' AND '2019-10-10'
AND PE.deleted = 0
LIMIT 3");
$getDatum->bindParam(':OID', $OID, PDO::PARAM_STR);
$getDatum->bindParam(':BeginDatum', $BeginDatum, PDO::PARAM_STR);
$getDatum->bindParam(':Einddatum', $Einddatum, PDO::PARAM_STR);
$getDatum->execute();
$docenten = array();
while ($row = $getDatum->fetch(PDO::FETCH_ASSOC))
{
$docenten[] = $row;
}
Pastebin link to code Because the code would otherwise be to long. Pastebin链接到代码,因为否则代码会很长。 I hope the information I gave is sufficient.
我希望我提供的信息足够。
You can store the time for event in DatumBegin or in a new column (suppose eventTime with format (H:i:s)
) and create three arrays according to time and then iterate them in different tr
您可以将事件的时间存储在DatumBegin或新列中(假设eventTime的格式为
(H:i:s)
),然后根据时间创建三个数组,然后在不同的tr
对其进行迭代
$morningTime = date("00:00:00");
$afternoonTime = date("12:00:00");
$eveningTime = date("17:00:00");
$morningEvents = [];
$afternoonEvents = [];
$eveningEvents = [];
while ($row = $getDatum->fetch(PDO::FETCH_ASSOC))
{
$dyDate = date($row['eventTime']);
if($dyDate<$afternoonTime){ // store "Morning Event";
$morningEvents[] = $row;
}
if($dyDate>=$afternoonTime && $dyDate<$eveningTime){ // store "Afternoon Event";
$afternoonEvents[] = $row;
}
if($dyDate>=$eveningTime){ // store "Evening Event";
$eveningEvents[] = $row;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.