0

I found an online tutorial at this website how to create an online calendar

http://davidwalsh.name/php-calendar
http://davidwalsh.name/php-calendar-controls

In comments to the website several people showed how to highlight the current day it worked for them how some but does not for me I tried the following codings

Code 1:

//Change this code:

 for($list_day = 1; $list_day <= $days_in_month; $list_day++):
 29
 $calendar.= '’;
 30
 /* add in the day number */
 31
 $calendar.= ”.$list_day.”;

//To this:

 for($list_day = 1; $list_day <= $days_in_month; $list_day++):
 if($list_day == $today && $month == $nowmonth && $year == $nowyear) {
 $calendar.= '’;
 } else {
 $calendar.= ”;
 }
 /* add in the day number */
 $calendar.= ”.$list_day.”;

I tried this code from this guys website http://www.rpetechnologies.com/calendar/code.php

/* keep going with days.... */
    for($list_day = '1'; $list_day <= $days_in_month; $list_day++): 
    if($list_day == $today && $month == $nowmonth && $year == $nowyear) {
      $calendar.= '<td class="calendar-day-today" onclick=window.location.href="viewday.php?d='.$list_day.'&m='.$month.'&y='.$year.'">';
      } else {
        //$calendar.= '<td class="calendar-day" onclick=window.location.href="viewday.php?d='.$list_day.'&m='.$month.'&y='.$year.'">';
        $calendar.= '<td class="calendar-day">';
        }
            /* add in the day number */
        $calendar.= '<div class="day-number">'.$list_day.'</div>';    

       $y = 0;
       if(strlen($x) == '1') {$x = $y.$x; }
       
    
            /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !!  IF MATCHES FOUND, PRINT THEM !! **/
            $todaydate = $year.'-'.$month.'-'.$x;
    $query = "SELECT * FROM `events` WHERE '$todaydate' >= event_start AND '$todaydate' <= event_end";
  $results = mysql_query($query) or die (mysql_error());
            if (mysql_num_rows($results) > '0') {
              while($row = mysql_fetch_array($results)){ 
              extract($row);      
       $catquery = "SELECT * FROM categories WHERE id=$catid";
       $catres = mysql_query($catquery) or die (mysql_error());
       $catrow = mysql_fetch_array($catres);
       $cat = $catrow['color'];
     $calendar.= '<div style="margin-top:2px; height:10px; width:10px; float:left; background:'.$cat.'">&nbsp;</div><div class="calendar-text"><a href="viewevent.php?id='.$id.'" rel="shadowbox;width=400;height=330">'.$event.'</a></div>';

Code 3:

// check today day & the current month
 if ($list_day == date(‘j’) && $month == date(‘m’))
 $calendar.= ”.$list_day.”;
 else
 $calendar.= ”.$list_day.”;

here is my current coding with undefinied variable Slist_day

<?php
		/* draws a calendar */
		function draw_calendar($month,$year){

		/* draw table */
		$calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';

		/* table headings */
		$headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
		$calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';

		/* 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.= '<tr class="calendar-row">';

		/* print "blank" days until the first of the current week */
		for($x = 0; $x < $running_day; $x++):
			$calendar.= '<td class="calendar-day-np">&nbsp;</td>';
			$days_in_this_week++;
		endfor;
		
		// check today day & the current month
		if ($list_day == date('j') && $month == date('m')) {
			$calendar.= '.$list_day.';
		} else {
			$calendar.= '$list_day';
		}

		/* keep going with days.... */
		for($list_day = 1; $list_day <= $days_in_month; $list_day++):
			$calendar.= '<td class="calendar-day">';
      
		/* add in the day number */
		$calendar.= '<div class="day-number">'.$list_day.'</div>';

		/** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !!  IF MATCHES FOUND, PRINT THEM !! **/
		$calendar.= str_repeat('<p>&nbsp;</p>',2);
      
		$calendar.= '</td>';
		if($running_day == 6):
			$calendar.= '</tr>';
		if(($day_counter+1) != $days_in_month):
			$calendar.= '<tr class="calendar-row">';
		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.= '<td class="calendar-day-np">&nbsp;</td>';
			endfor;
		endif;

		/* final row */
		$calendar.= '</tr>';

		/* end the table */
		$calendar.= '</table>';
  
		/* all done, return result */
		return $calendar;
		}

		/* Current month and year */
		$year = date ('Y'); $month_title = date ('F'); 
		$month_display = date ('n'); 
		
		/* sample usages */ 
		echo ''.$month_title.'&nbsp;'.$year.''; 
		echo draw_calendar($month_display,$year);
?>
2
Contributors
2
Replies
9
Views
6 Years
Discussion Span
Last Post by rusty813
0

jQueryUI has a good online calendar. Many other good js calendars/datepickers exist too.

If you got the code from another forum, perhaps you should try asking your questions there?

0

yea i did ask the question there but it looks like noone is paying attention to site any more so thats why i came down here

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.