PHP
  Home arrow PHP arrow Page 6 - 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... - The Final Touch


    (Page 6 of 6 )

    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):

    <? include("config.php"); // open a connection to the database $connection = mysql_connect($server, $user, $pass); // formulate the SQL query - same as above $query = "SELECT DISTINCT date from calendar where date >= '" . $currYear . "-" . sprintf("%02d", $currMonth) . "-01' and date <= '" . $currYear . "-" . sprintf("%02d", $currMonth) . "-" . $totalDays[$currMonth] . "'"; // run the query on the database $result = mysql_db_query($db,$query ,$connection); $x=0; $dateList=array(); if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_array($result)) { $dates = explode("-", $row["date"]); $dateList[$x] = $dates[2]; $x++; } } // close connection mysql_close($connection); ?>
    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...

    <? // counter to track the current date $dayCount=1; while ($dayCount <= $totalDays[$currMonth]) { // use this to find out when the // 7-day block is complete and display a new row if ($rowCount % 7 == 0) { echo "</tr>\n<tr>\n"; } // if today, display in different colour // print date if ($dayCount == date("j") && $currYear == date("Y") && $currMonth == date("n")) { 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>"; } else { echo "<td align=center><font face=Arial size=-1><a href=day.view.php?currYear=" . $currYear . "&currMonth=" . $currMonth . "&currDay=" . $dayCount . ">" . $dayCount . "</a></font>"; } // newly-added code to find out is appointment is already scheduled // and print indicator if so for ($y=0; $y<sizeof($dateList); $y++) { //echo $dateList[$y]; if ($dateList[$y] == $dayCount) { echo "<font face=Arial color=red size=-4>+</font>"; } } echo "</td>\n"; // increment counters $dayCount++; $rowCount++; } ?>

    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.
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

       

    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 3 hosted by Hostway
    Stay green...Green IT