Home arrow PHP arrow Page 2 - A Useful Event Calendar Written In PHP
PHP

A Useful Event Calendar Written In PHP


An events calendar allows you to keep a schedule of your appointments, etc. In this article Mitchell creates an extremely useful events calendar using only PHP.

Author Info:
By: Mitchell Harper
Rating: 4 stars4 stars4 stars4 stars4 stars / 196
June 10, 2002
TABLE OF CONTENTS:
  1. · A Useful Event Calendar Written In PHP
  2. · The event calendars logic
  3. · Creating the calendar
  4. · Highlighting days with events
  5. · Adding an event
  6. · Conclusion

print this article
SEARCH DEVARTICLES

A Useful Event Calendar Written In PHP - The event calendars logic
(Page 2 of 6 )

As the name suggests, an events calendar stores events. These events are shown along with the calendar when a specific day is selected, such as the 11th June, 2002. The calendar will display events in a "by month" format, meaning that each of the thirty or so days for a month will be shown on one page. If any of the days have events "attached" to them, then that day will be highlighted in blue. Likewise, today's date will be highlighted in grey, and the currently selected day (if any) will be highlighted in red.

If we click on a day, then all of the events attached to that day will be displayed, along with a form through which we can add a new event. All events include a link to remove them.

So, just to get you excited, here's what the calendar will look like when we're finished:

A sneak preview of our calendar

Today is the 11th, so see how June 11th is highlighted in grey? The PHP code to drive our calendar will be stored in one file called cal.php. Cal.php will work with a flat text file called cal_events.text. Cal_events.text will contain the list of events for our calendar. Each event is stored in the following format:

[Month] [Day] [Year]
[Event Name]
[Event Description]

So if I had an event reminding me that today is the 11th of June, then it would be stored in cal_events.text like this:

06 11 2002
Today is the 11th Of June!
Guess what, today is the 11th of June. Woohoo!

Each entry takes up three rows, and we can use PHP's powerful file and array functions to effortlessly grab each event from the flat file and display/delete it accordingly.

Cal.php is separated into three different sections:
  • Add Post: The AddPost() function allows us to add an event to a specific day of our calendar.
  • Delete Post: The DelPost() function allows us to delete an event from our calendar.
  • Display Calendar: We display the calendar by making use of PHP’s powerful date manipulation functions, by using for loops, and also by opening the events file and flagging particular days that contain events, etc.
Each day in a particular month is represented as part of a table as a <td> cell. The calendar was designed to take advantage of Internet Explorer's Cascading Style Sheet (CSS) abilities, so at the top of cal.php I have defined some styles for various parts of the calendar:

.normal {
font-family: Verdana;
font-size: 8pt;
color: #000000;
height: 20;
padding-left: 5pt;
}


This style is used for normal days. By a normal day I mean a day that isn't today and a day that contains no events.

.today {
font-family: Verdana;
font-size: 8pt;
color: #FFFFFF;
background-color: #CACACA;
height: 20;
padding-left: 5pt;
}


This style is used to highlight the current day, making it easy to work out what the day is and how many days there are until the end of the month, etc.

.selected {
font-family: Verdana;
font-size: 8pt;
color: #FFFFFF;
background-color: #C00000;
height: 20;
padding-left: 5pt;
}


When we click on a day to view its events, this style will highlight it in a bright red, making it stand out from the rest of the days around it.

.event {
font-family: Verdana;
font-size: 8pt;
color: #000000;
background-color: #C6D1DC;
height: 20;
padding-left: 5pt;
}


Lastly we have the event style, which is used for any day that is attached to one/more events from the events file.

After adding a couple of events and selecting a day, here's how our calendar will look:

Our calendar in action

In the screen shot above, days 12, 24 and 28 contain events. It is the 11th of June, so the 11th is highlighted in grey, and we have the 12th day selected, so it is highlighted in red. Note the events for the 12th are shown under the "Today's Events" section just under the calendar.

Well now that we know a bit more about how the calendar functions, let's jump right in and take a look at how to code up the calendar.
blog comments powered by Disqus
PHP ARTICLES

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials