Я делаю календарь в PHP для своего проекта. У меня есть стиль для календаря и страницы на текущий месяц, но я не могу понять, как добавить кнопку «Следующий месяц».
Ниже я включил код PHP, который у меня есть на данный момент.
<?php
function build_calendar($month, $year, $conn) {
//array for names of all days
$days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thurdsday', 'Friday', 'Saturday');
//first day of the month
$day1 = mktime(0,0,0,$month,1,$year);
//the number of the days in the month
$numberDays = date('t', $day1);
//info of the first day of this month
$dateComponents = getdate($day1);
//name of the month
$monthName = $dateComponents['month'];
//index value 0-6 of thr first day of the month
$weekday = $dateComponents['wday'];
//current date
$dateToday = date('Y-m-d');
//create the html table
$calendar = "<table class='table table-bordered'>";
$calendar.="<Center><h2>$monthName $year</h2>";
$calendar.="<tr>";
//calendar headers
foreach($days as $day){
$calendar.="<th class='header'>$day</th>";
}
$calendar.= "</tr><tr>";
//must only be 7 columns in the table
if($weekday > 0){
for($k=0;$k<$weekday;$k++){
$calendar.="<td></td>";
}
}
//day counter
$currentDay = 1;
//get the month number
$month = str_pad($month,2,"0", STR_PAD_LEFT);
while($currentDay<=$numberDays){
//if seven columns reached, start a new row
if($weekday == 7){
$weekday = 0;
$calendar.="</tr><tr>";
}
$currentDayRel = str_pad($currentDay,2,"0", STR_PAD_LEFT);
$date = "$year-$month-$currentDayRel";
$dayName = strtolower(date('I', strtotime($date)));
$today = $date==date('Y-m-d')?"today":"";
if($date<date('Y-m-d')){
$calendar.="<td><h4>$currentDay</h4><button class='btn btn-danger btn-xs'>N/A</button>";
}else if($weekday == 0 or $weekday == 6){
$calendar.="<td><h4>$currentDay</h4><button class='btn btn-danger btn-xs'>N/A</button>";
}else if(in_array($date, $bookings)){
$calendar.="<td><h4>$currentDay</h4><button class='btn btn-success btn-xs'>Limited Spaces</button>";
}else{
$calendar.="<td class='$today'><h4>$currentDay</h4><a href='book.php?date=".$date."'class='btn btn-success btn-xs'>Book</a>";
}
$calendar.="</td>";
//increment the counters
$currentDay++;
$weekday++;
}
//row of the last week in the month
if($weekday!=7){
$remainingDays = 7-$weekday;
for($i=0;$i<$remainingDays;$i++){
$calendar.="<td></td>";
}
}
$calendar.="</tr>";
$calendar.="</table>";
echo $calendar;
}
?>
Я довольно новичок в PHP, поэтому я не могу решить эту проблему. Любая помощь будет принята с благодарностью.