25.07.2024
Home / News / Incorrect calendar php. How to write a php calendar for the month and year? PHP calendar script in Russian style

Incorrect calendar php. How to write a php calendar for the month and year? PHP calendar script in Russian style

One of the important elements on the site is the calendar, with which your users can track events and new product releases. Or just read the notes or whatever else you can think of. After spending some time in this lesson, you will learn how to create a PHP calendar script for your website. We will not limit ourselves only to programming; we will also pay attention to the CSS and html structure of the calendar. In a word, we will do everything, from start to finish!

CSS

Talk less, work more. Let's immediately start with the css styles of the calendar. The code below is compatible with the problematic IE6 browser.

/* calendar */ table.calendar ( border-left:1px solid #999; ) tr.calendar-row ( ) td.calendar-day ( min-height:80px; font-size:11px; position:relative; ) * html div.calendar-day ( height:80px; ) td.calendar-day:hover ( background:#eceff5; ) td.calendar-day-np ( background:#eee; min-height:80px; ) * html div. calendar-day-np ( height:80px; ) td.calendar-day-head ( background:#ccc; font-weight:bold; text-align:center; width:120px; padding:5px; border-bottom:1px solid #999; border-top:1px solid #999; border-right:1px solid #999; ) div.day-number ( background:#999; padding:5px; color:#fff; font-weight:bold; float: right; margin:-5px -5px 0 0; width:20px; text-align:center; td.calendar-day, td.calendar-day-np ( width:120px; padding:5px; border-bottom:1px solid #999; border-right:1px solid #999;

PHP

The entire PHP calendar script code is basically based on a single function that requires two parameters: the desired month and year. It should be noted that in the middle of the function, I left space for the database. If you want, you can display the necessary events in the calendar grid. When writing this script, I used tables instead of div blocks, as they are more practical in case one day is full of events.

The English-language calendar script was taken as a basis, so I will provide two versions: a calendar in English and Russian style. Choose which one you like! The only difference is in the PHP code. CSS styles remain the same for both options.

PHP calendar script in Russian style "; /* Headings in the table */ $headings = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"); $calendar.= " "; /* required day and week variables... */ $running_day = date("w",mktime(0,0,0,$month,1,$year)); $running_day = $running_day - 1; $ days_in_month = date("t",mktime(0,0,0,$month,1,$year)); $days_in_this_week = 1; $day_counter = 0; $dates_array = array(); /* first row of the calendar */ $calendar.= " < $running_day; $x++): $calendar.= "

Conclusions Thus, we have a simple and easily embedded event calendar that works quickly and is easy to customize, running in pure PHP+javascript without additional libraries.
".implode("",$headings)."