There's one more thing you can do to make this calendar a little more useful - display an indicator in "month view" to identify which days already have appointments scheduled, and which days are completely free of appointments. In order to do this, go back to "month.view.php" and add the following lines of code to it, somewhere near the beginning of the script (but after you've defined $currDay, $currMonth, and $currYear): What have I done here? I've used the three variables to formulate a query which returns a list of all the days in $currMonth which already have appointments scheduled (the DISTINCT keyword helps to eliminate duplicate entries). Then I've taken each of those date strings (in the form YYYY-MM-DD), split them into separate entities, and created an array called $dateList which contains a list of all the days on which appointments are scheduled. The plan is to add an additional check to the sections of code responsible for generating the dates in the month, such that dates which match the elements in the $dateList array have an additional identifier to indicate that something is already scheduled for that day. You saw earlier that I had separated the date and time into separate columns when creating the database table. One of the primary reasons behind this was to simplify the task of obtaining a list of dates which had one or more appointments scheduled. If the date and time had been combined into a single column, the DISTINCT keyword would have failed to eliminate duplicate entries, and I would have had to write a lot more code to weed out the duplicates. And we already know how lazy I am...
And here's what the finished product looks like: ![]() And that's about it. You can now begin using this calendar, as is, for keeping track of your life; modify it as per your requirements; or use it as an entry point to other applications. And if you're new to PHP, this tutorial should hopefully have offered you some insight into how Web applications are developed, and maybe even sparked some ideas of your own. If so, let me know...and till next time, stay healthy! This article copyright Melonfire 2001. All rights reserved.
blog comments powered by Disqus |