Blogroll

Wednesday, April 11, 2012

Display Calendar Php Code

One of the website features my customers love to provider their web users is an online dynamic calendar. An online calendar can be used for events, upcoming product specials, memos, and anything else you can think of. I've taken some time to completely rewrite the PHP event calendar so that I may share it with you.
function draw_calendar($month,$year){

  /* draw table */
  $calendar = '';

  /* table headings */
  $headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  $calendar.= '';

  /* days and weeks vars now ... */
  $running_day = date('w',mktime(0,0,0,$month,1,$year));
  $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
  $days_in_this_week = 1;
  $day_counter = 0;
  $dates_array = array();

  /* row for week one */
  $calendar.= '';

  /* print "blank" days until the first of the current week */
  for($x = 0; $x < $running_day; $x++):
    $calendar.= '';
    $days_in_this_week++;
  endfor;

  /* keep going with days.... */
  for($list_day = 1; $list_day <= $days_in_month; $list_day++):
    $calendar.= '';
    if($running_day == 6):
      $calendar.= '';
      if(($day_counter+1) != $days_in_month):
        $calendar.= '';
      endif;
      $running_day = -1;
      $days_in_this_week = 0;
    endif;
    $days_in_this_week++; $running_day++; $day_counter++;
  endfor;

  /* finish the rest of the days in the week */
  if($days_in_this_week < 8):
    for($x = 1; $x <= (8 - $days_in_this_week); $x++):
      $calendar.= '';
    endfor;
  endif;

  /* final row */
  $calendar.= '';

  /* end the table */
  $calendar.= '

'.implode('',$headings).'
'; /* add in the day number */ $calendar.= '
'.$list_day.'
'; /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/ $calendar.= str_repeat('

',2); $calendar.= '
'; /* all done, return result */ return $calendar; } /* sample usages */ echo '

July 2009

'; echo draw_calendar(7,2009); echo '

August 2009

'; echo draw_calendar(8,2009);
Source:http://davidwalsh.name/php-calendar
Olá! Se você ainda não assinou, assine nosso RSS feed e receba nossas atualizações por email, ou siga nos no Twitter.
Nome: Email:

1 comments:

Vivek said... at July 23, 2012 at 11:43 AM

Good guidance..And i would like to refer my friends also who are looking up for this.
Hire Magento Developer

Post a Comment