我正在开发自己的日历事件。一切都很好,但现在我遇到了一些问题。将活动添加到日历中php
这是我的代码:
<?php
$timestamp = mktime(0, 0, 0, $cMonth, 1, $cYear);
$maxday = date("t", $timestamp);
$thismonth = getdate($timestamp);
$thisyear = getdate($timestamp);
$startday = $thismonth['wday'];
for ($i = 0; $i < ($maxday + $startday); $i++) {
$date = ($i - $startday + 1) . $cMonth . $cYear;
if (($i % 7) == 0)
;
if ($i < $startday)
;
elseif (($i - $startday + 1) == $cDay && $cMonth && $cYear) {
echo "<div class='currentDate'>" . ($i - $startday + 1) . "<br /></div>";
} else {
echo "<a href='?day=" . ($i - $startday + 1) . "&month=" . $cMonth . "&year=" . $cYear . "'><div class='date'>" . ($i - $startday + 1) . "</div></a>";
}
$result = $MySQLi_CON->query("SELECT * FROM events");
while ($row = $result->fetch_array()) {
$event_date2 = $row['event_date'];
$date2 = date("Y-m-d", strtotime($event_date2));
if (($i - $startday + 1) == $date2) { // Check if the date is the same
echo "<div class='date'><a href='#'>" . $date2 . "</a></div>"; // Show the event date.
}
}
}
?>
我试图与来自在MySQL表“事件”日期日历每天匹配。日历中与事件中的日期匹配的每个日期都应显示此事件。
编辑:其余代码:
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
if(!isset($_REQUEST['day'])) $_REQUEST['day'] = date('d');
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
// Rest of code
$cDay = $_REQUEST['day'];
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
// Rest of code
?>
那么你的问题究竟是什么? – jiboulex
问题是我的代码显示“event_date”的每个日期。 – user3219200
数据库中的日期字段是以时间戳,日期时间还是日期存储的? – jiboulex