Logo         Community
The Company
Your Account
Contact Us
Miles To Go Before I Sleep...
Take PHP out of the classroom and into the real world, with this case study of building a Web-based appointment calendar.

| January To December, And Everything In Between |

Now, by itself, this isn't very useful, since it only displays information for the current month (as determined by the server's clock). My next task, therefore, is to make it possible to move forwards and backwards through the year, by activating the "next" and "previous" links on the first row.

In order to do this, I need to define a few new variables, which will be used to identify the previous and next month and year.

// set up variables to display previous and next months correctly

// defaults for previous month
$prevMonth = $currMonth-1;
$prevYear = $currYear;

// if January, decrement year and set month to December
if ($prevMonth < 1)

// defaults for next month
$nextMonth = $currMonth+1;
$nextYear = $currYear;

// if December, increment year and set month to January
if ($nextMonth > 12)

Note the correction that has to take place if the month in question is either January or December.

Once those variables are defined, it's a simple matter to activate the links on the top row of the calendar. The variables are passed back to the script using the GET method.

<table border="0" cellpadding="2" cellspacing="5">
<!-- month display -->
<!-- this is the first row of the calendar, with links active -->
<td><a href="<? echo $PHP_SELF; ?>?currMonth=<? echo $prevMonth;
?>&currYear=<? echo $prevYear; ?>"><font face="Arial"

<td colspan="5" align="CENTER"><font face="Arial" size="-1"><b><? echo
$months[$currMonth] . " " . $currYear; ?></b></font></td>

<td><a href="<? echo $PHP_SELF; ?>?currMonth=<? echo $nextMonth;
?>&currYear=<? echo $nextYear; ?>"><font face="Arial"

You should now have a calendar capable of displaying information for any month of any year.

The next task is to convert each date on the calendar into an active link, which, when clicked, will display the user's current appointments for that day, together with the option to add new appointments. This intelligence will be built into a file called "day.view.php", which requires three parameters - the year, month and date under consideration. So let's make that modification to the code above:

// if today, display in different colour

// print date, each date is now an active hyperlink
if ($dayCount == date("j") && $currYear == date("Y") && $currMonth ==
echo "<td align=center bgcolor=Silver><font face=Arial size=-1><a
href=day.view.php?currYear=" . $currYear . "&currMonth=" . $currMonth .
"&currDay=" . $dayCount . ">" . $dayCount. "</a></font>";
echo "<td align=center><font face=Arial size=-1><a
href=day.view.php?currYear=" . $currYear . "&currMonth=" . $currMonth .
"&currDay=" . $dayCount . ">" . $dayCount . "</a></font>";

All done? Here's what it looks like.

Output image

Let's move on to the "day view".

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback