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
PHP Web Logs (BLogs)
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
Submit Site
Forex Trading Online forex trading platform

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 : 4 of 5 (graded 4 times)
Viewed : 11304
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);
}
?>



Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example.
Categories : PHP, Date Time, PHP Classes, 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
Shows the current time as a PNG-image. This script does not use the GD library. You can use it as a benchmark (because it's slow), or as a quick reference for implementing a simple PNG-file generator.
Categories : Graphics, Zlib, Calendar, PHP, Date Time
CALENDAR - easy calendar-navigation with PHP
Categories : PHP, Date Time, HTML and PHP, Calendar
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
Count how many weeks in the month have a specified day, such as Mon, Tue, etc. Var avail - number of days - first day name of the month, occurrences of Sun, occurrences of Mon, etc. Allows you to calculate number of working hours exclude Holidays.
Categories : Calendar, Date Time, PHP, Databases, MySQL
PHP Calendar
Categories : PHP, Calendar, Date Time, Java Script, CSS
Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June).
Categories : Calendar, Date Time, PHP
Calendar class on the same page , suitable for reservation
Categories : PHP, Calendar, Date Time
function to generate calendars on the fly.
Categories : Calendar, PHP, Date Time
Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP, Date Time, PHP Classes
Monthly and Daily Upcoming Events calendar.
Categories : Date Time, PostgreSQL, PHP, Calendar, Databases
Open and Close your website in fixed times .
Categories : PHP, PHP Classes, Cron, Date Time
Generate HTML Calendar of a month of year
Categories : PHP, Calendar, PHP Classes