PHP
  Home arrow PHP arrow Page 2 - Miles To Go Before I Sleep...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Miles To Go Before I Sleep...
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2001-02-05

    Table of Contents:
  • Miles To Go Before I Sleep...
  • Building The Foundation
  • Seven Days, Seven Nights
  • Bringing In The Database
  • Adding, Editing, Deleting...
  • The Final Touch

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Miles To Go Before I Sleep... - Building The Foundation


    (Page 2 of 6 )

    The calendar we're going to build should have both a "month view" and a "day view" - selecting a specific day from the month view should display scheduled appointments for that day. Options should be available to add new appointments to the list, or edit and delete existing appointments.

    This is a good time for you to download the source code, so that you can refer to it throughout this tutorial (you will need a Web server capable of running PHP and a mySQL database in order to run the application).

    calendar.zip

    We'll begin with the month view, a file I'm going to call "month.view.php". The first thing to do is seta few variables which decide the month and year to be displayed - these variables will be used throughout the application, and are crucial to it functioning correctly. PHP's date() function is perfect for obtaining this information:

    <? // set up some variables to identify the month, date and year to display if(!$currYear) { $currYear = date("Y"); } if(!$currMonth) { $currMonth = date("n"); } if(!$currDay) { $currDay = date("j"); } ?>

    Thus, the variables $currDay, $currMonth and $currYear will hold the values corresponding to the current date, month and year respectively. For example, on 25 January 2001, the variables would look like this:

    <? $currYear = 2001; $currMonth = 1; $currDay = 25; ?>
    The date() function comes with numerous modifiers which allow you to extract just those specific segments of the date and time you need from a standard UNIX timestamp. This is a feature I'll be using a lot as I begin building my application, so if you're not familiar with it, take a look at the PHP4 date() function reference at before reading further.

    Next, it's time to set up some friendly names for the various months of the year and days of the week - these will come in handy when displaying the calendar.


    <? // list of names for days and months $days = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); // number of days in each month $totalDays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // if leap year, modify $totaldays array appropriately if (date("L", mktime(0,0,0,$currMonth,1,$currYear))) { $totalDays[2] = 29; } ?>
    Yup, the date() function even lets you find out if the year under consideration is a leap year - if it is, it's necessary to modify the $totalDays array for the month of February. Since the date() function only works on a correctly-formatted UNIX timestamp, the mktime() function is used to first convert the numeric month and year into an acceptable format.

    Before getting into the calendar display, there's one more thing needed: the day of the week on which the first of the month falls.

    <? // find out which day the first of the month falls on $firstDayOfMonth = date("w", mktime(0,0,0,$currMonth,1,$currYear)); ?>
    The first day of the month (from the $firstDayOfMonth variable) and the last day (from the $totalDays array) provide the bounding values for the month view I'm going to be building.

    This article copyright Melonfire 2001. All rights reserved.

    More PHP Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT