Jump to content


Photo

Calendar function with links


  • Please log in to reply
1 reply to this topic

#1 sivarts

sivarts
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 26 August 2006 - 06:45 AM

Hi Folks. Wondering if any one can help me out here.

I've done a tutorial posted on the Adobe Developer center to build a simple calendar that will 'link' the days that have events to those events. Catch my drift (kinda tired...)? I have gone over the code so many times and even  copy/pasted the code from the examples provided from MacroDobia. Basically, I have a recordset that gets all the dates (in MySQL format) for the events (named getEvtDates) and dumps them into an array (see below $dates). I know that the recordset is working and the array is being created (simply with print_r($dates); ) but I still don't have any links in my calendar. Anyone have some time to help me out? It's pretty frustrating...
P.S. I am using Dreamweaver to generate most of my code (which I am really good about reading and modifying).

Here's the code with some comments...

<?php 
			function build_calendar($month,$year,$day) {
				/* Declaring the variables */
				$daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');
				$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
				$noDays = date('t',$firstDayOfMonth);
				$dateComponents = getdate($firstDayOfMonth);
				$dayOfWeek = $dateComponents['wday'];
				$monthName = date('F',mktime(0,0,0,$month,1,$year));
				
				global $getEvtDates; //this is the name of the recordset
				global $_GET;
				
				if (mysql_num_rows($getEvtDates) > 0) {
				mysql_data_seek($getEvtDates,0);
				while ($row_getEvtDates = mysql_fetch_assoc($getEvtDates)) {
				$dates[] = $row_getEvtDates['event_date']; 
				}
				}
				/* Computing the previous month. */
				if($month == 1) {
				 	$mn=12;
				 	$yn=$year-1;
			 	} else {
				 		$mn=$month-1;
				 		$yn=$year;
				}
				
				/* Computing the next month. */
				if($month == 12) {
					$mn2=1;
					$yn2=$year+1;
				} else {
					$mn2=$month+1;
					$yn2=$year;
				}
				
				/* Calendar header: next and previous month links */
				$calendar = "<table>";
				$calendar .= "<tr><td><p><a href=get_days_events.php?y=$yn&m=$mn&d=$day>&lt;</a></p></td>";
				$calendar .="<td colspan=5 align=center><p><strong>$monthName, $year</strong></p></td>";
				$calendar .="<td><p><a href=get_days_events.php?y=$yn2&m=$mn2&d=$day>&gt;</a></p></td></tr>";
				$calendar .="<tr>"; 		
				
				/* Calendar header: Display the days of the week */
				foreach($daysOfWeek as $day) { 
			          $calendar .= "<td><p>$day</p></td>";
				} 
				$calendar .= "</tr>"; 
				$calendar .= "<tr>"; 

			  $currentDay = 1;
			 

			  /* Fill in the beginning of the calendar	body */    
			  if ($dayOfWeek > 0) {  
			     $calendar .= "<td  colspan='$dayOfWeek'>&nbsp;</td>";  
			  } 
			
			  /* Generate the calendar body */		
			  while ($currentDay <= $noDays) {
                 if ($dayOfWeek == 7) {
                     $dayOfWeek = 0;
                     $calendar .= "</tr><tr>";
                 }
				 $date = $year."-".$month."-".$currentDay; //here's where the trouble might start
				 if (in_array($date,$dates)) {
                  $calendar .= "<td><p><a href='get_days_events.php?y=$year&m=$month&d=$currentDay'>$currentDay</a></p></td>";
				  } else {
				  $calendar .= "<td><p>$currentDay</p></td>";
				  }
               
               $currentDay++;
               $dayOfWeek++;
				}
			/* Filling in the end of the calendar body */
			if ($dayOfWeek != 7) {  
		          $remainingDays = 7 - $dayOfWeek; 
        		  $calendar .= "<td colspan='$remainingDays'>&nbsp;</td>";  
			} 
  
  			$calendar .= "</table>"; 
			return $calendar;
} 
if (isset($_GET['m']) && isset($_GET['y']) && isset($_GET['d'])){	 
	$month = $_GET['m'];
	$year = $_GET['y'];
	$day = $_GET['d'];
} else {
	$dateComponents = getdate();
	$month = $dateComponents['mon'];
	$year = $dateComponents['year'];
	$day = $dateComponents['mday'];
}

echo build_calendar($month,$year,$day);

		?>

I know it will be difficult to test this out since you do not have records to play with. But hopefully some one can notice what I am missing. CHEERS (and goodnight!)

#2 sivarts

sivarts
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 August 2006 - 11:27 PM

Can anyone please help??




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users