Hello I'm trying to create my own calendar with just php, but I'm running into a problem. This is the top part of my calendar where I have 2 icons. one backwards and one forward arrow. just like in any calendar I want to be able to press those buttons and that the code will change the month to , in this case if you press the backward icon, April. The opposite for the forward arrow.
$sql = "SELECT * FROM reserveringen";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$start_datum = $row['start_datum'];
$eind_datum = $row['eind_datum'];
echo $start_datum;
echo "<br>";
echo $eind_datum;
}
$date = new DateTime();
if (isset($_POST['monthBack'])) {
$date = $date->add(new DateInterval('-1 month'));
}
else if (isset($_POST['monthFuture'])) {
$date = $date->add(new DateInterval('P1W2D'));
}
$calendarTiming = $date->format('d-m-Y');
$currentMonth = $date->format('m');
$year = $date->format('Y');
$dagenCheck = cal_days_in_month(CAL_GREGORIAN, $currentMonth, $year);
echo "<br>";
echo "<thead>";
echo "<tr>";
echo "<th colspan='7'>
<form method='POST' action=''>
<input type='hidden' name='currentMonth' value='$currentMonth'>
<button type='submit' name='monthBack'>
" style="font-size: 20px">
</button>";
print_r($calendarTiming);
echo " ".
"<button type='submit' name='monthFuture'>
^__i class='fa fa-angle-right' style='font-size: 20px;'>
</button>
</form>
</th>";
echo "</tr>";
echo "<br>";
but this code only works for one month back ward and/or forward.
so the only months I'm getting are 18-04-2022 , 18-05-2022 and 18-06-2022. But I want to be able to just scroll trough the months like and actual online calendar. is this possible in php?
it also doesn't update itself in this part
echo "<th colspan='7'>
<form method='POST' action=''>
<input type='hidden' name='currentMonth' value='$currentMonth'>
<button type='submit' name='monthBack'>
" style="font-size: 20px">
</button>";
print_r($calendarTiming);
echo " ".
"<button type='submit' name='monthFuture'>
^__i class='fa fa-angle-right' style='font-size: 20px;'>
</button>
</form>
</th>";
it just keeps it the same date
What I have tried:
Tried to look it up on stack overflow but I got no results.
I also tried to put the if isset month back and the month future above the thead with the other date functions
but that only gives
18-04-2022 or 18-06-2022