WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Categories : PHP, PHP Classes, Calendar, Date Time Click here to Update Your Picture
Rupali Gulande
Date : Jul 28th 2007
Grade : 3 of 5 (graded 6 times)
Viewed : 29672
File : 4686.zip
Images : Image 1
Search : More code by Rupali Gulande
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

In this example we are going to design a calendar which we store in a php file and then we can call it to any php page by using the following code :

<?php
include "calendar_class.php";
$file = basename($_SERVER['PHP_SELF']);
echo
calendar($file);
?>

see code for calender function

<?php

function calendar($file){

    if((isset(
$_GET['d']))?$day=$_GET['d']:$day = date("d"));
    if((isset(
$_GET['m']))?$month=$_GET['m']:$month = date("m"));
    if((isset(
$_GET['y']))?$year=$_GET['y']:$year = date("Y"));

//create arrays for the calendar

   
$months_days = array("31","28","31","30","31","30","31","31",
                         
"30","31","30","31");
   
$months_name = array("Jan","Feb","Mar","Apr","May","Jun","Jul",
                         
"Aug","Sep","Oct","Nov","Dec");
   
$days_array = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");

//removes the 0 from start of month - can't find array key with 0

   
if(strlen($month)==1){
       
$month= str_replace("0","",$month);
    }
    else{
       
$month=$month;
    }

//reset month to the array key match (array starts at 0)

   
$month= $month-1;

//find the days in the month

   
$days_in_month = $months_days[$month];

//And convert the month number to name

   
$month_name = $months_name[$month];

//$m is used to find month

   
$m = $month+1;

//find the first day of the month     
 
   
$time = date("M D Y H:i:s", mktime(0, 0, 0, $m, 1, $year));
   
$first_day = explode(" ",$time);
   
$time = $first_day[1];

//create the links to next and previous months

   
$next = $month+2;
   
$x = $year;

//if month is 13 then new year

   
if($next==13){
       
$next=1;
       
$x = $x+1;
    }
   
$prev = $month;
   
$y = $year;

//if month is 0, then previous year

   
if($prev==0){
       
$prev=12;
       
$y=$y-1;
    }

   
$calendar = "";

//Build the calendar with css
//links to next and previous month

   
$calendar .='
                <div class="calendar">
                  <div class="calhead">
                    <div class="right">
                      <a href="'
.$file.'?m='.$next.'&y='.$x.'&d='.$day.'">>></a>
                    </div>
                    <div class="left">
                      <a href="'
.$file.'?m='.$prev.'&y='.$y.'&d='.$day.'"><<</a>
                    </div>   
                    <div class="middle"><span>'
.$month_name.'/'.$year.'</span></div>
                    </div>
                    <div class="caldays">
                      <ul class="days">
                        <li>M</li>
                        <li>T</li>
                        <li>W</li>
                        <li>T</li>
                        <li>F</li>
                        <li>S</li>
                        <li>S</li>
                      </ul>
                    </div>
                    <div class="caldates">
                      <ul class="dates">
              '
;
               
   
//checks for leap years and add 1 to February

   
if(($year % 4 =="") && ($month==1)){
       
$days_in_month=$days_in_month+1;
    }

    else{
       
$days_in_month=$days_in_month;
    }

   
$new_time="";
     
   
//find how many blank spaces at beginning of the month
     
   
foreach($days_array as $key=>$value){
     
        if(
$value == $time){
           
$new_time .= $key+1;
        }
        else{
           
$new_time .="";
        }
    }
     
   
//loop through the days in the month
             
   
for($k=1;$k<($days_in_month+$new_time);$k++){   
     
           
//blank space
     
       
if($k<$new_time){
           
$calendar.='<li class="blank"></li>
            '
;
            continue;
        }
         
       
//start the actual days
             
       
$n = $k-$new_time+1;
                 
        if(
$n==$day){
           
$calendar .= '<li><b>'.$n.'</b></li>
                         '
;   
        }
        else{
           
$calendar .= '<li>'.$n.'</li>
                         '
;
        }     
    }
   
$calendar .= '</ul>
                 '
;

   
//reset for link to today

   
$d = date("d");
   
$m = date("m");
   
$y = date("Y");
   
$calendar .=' <div class="today"><a href="'.$file.'?d='.$d.'&m='.$m.'&y='.$y.'">today</a></div></div></div>';
    return(
$calendar);
}
?>



pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example.
Categories : PHP, Date Time, PHP Classes, Calendar
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
Generate HTML Calendar of a month of year
Categories : PHP, Calendar, PHP Classes
Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June).
Categories : Calendar, Date Time, PHP
Monthly and Daily Upcoming Events calendar.
Categories : Date Time, PostgreSQL, PHP, Calendar, Databases
PHP Calendar
Categories : PHP, Calendar, Date Time, Java Script, CSS
This script contains 2 functions: 1 to create html select object based on your own customer date format entry- "M d Y h:i.... etc". The second function processes the select object on submit back to unix time.
Categories : PHP, Calendar, Date Time, HTML and PHP
PHP Calendar Web App
Categories : PHP, Databases, MySQL, Date Time, Calendar
Calendar, Kalender, date, time, day, month, year
Categories : PHP, Date Time, Calendar
Validator - A PHP class that can can be used for validating Email IDs and Dates
Categories : PHP, PHP Classes, Data Validation, Email, Date Time
A Timing Class
Categories : PHP, PHP Classes, Date Time
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
A simple and fast calendar combining PHP and tables. Use this as a base for applications in which a calendar is needed.
Categories : Date Time, PHP, Complete Programs, Calendar
Calendar class on the same page , suitable for reservation
Categories : PHP, Calendar, Date Time