First learn how to display calendar for any month. By modifying this script we will display a yearly calendar showing all 12 months.
Here we will not read the month from query string. We will use one for loop to take the variable value from 1 to 12.
for($m=1;$m<=12;$m++){
$month =date($m); // Month
$dateObject = DateTime::createFromFormat('!m', $m);
$monthName = $dateObject->format('F'); // Month name to display at top
This value will use as Month and display the calendar by using the month value.
Year part we will fix to 2016, but you can change year to any other value to display that year calendar.
$year=2016; // change this to another year
Now we are reading month value from for loop and year directly so in this script we have removed the dropdown selection box for month and year.
Adding a table
Now we will keep one main table (outer table ) to contain all the calendars. We will set another variable $row. The value of $row will increment by 1 on each loop. Once the value reaches 3 then we will introduce one row.
if(($row % 3)== 0){
echo "</tr><tr>";
}
In the above code we check the modulus of value of $month % 3 and if it is equal to zero then it will add one row. You can change this value ( from 3 ) to any other value to display that many calendars in a row.
This way we can add one row in outer table after displaying three calendars.
This script is included in Zip file.
Changing the stating day of the week
We can start the week from Monday and accordingly the calendar can be changed. The modification required for the same is explained in basic tutorial for monthly calendar.
The modified script year-calendar3.php to show yearly calendar with Monday as starting weekday is included in your zip file .
.
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
Two lines are to be added and the Header row is to be changed. This part is added to main calendar tutorial showing monthly calendar now. Inside your zip file one new calendar ( cal3.php ) is added which shows week starting from Mondays.
✖
We use cookies to improve your browsing experience. . Learn more