(Self Solved) Need some help with my calendar..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

(Self Solved) Need some help with my calendar..

Post by Zoxive »

Im making a Calendar for a site im working on, and on certain days im gong to have like a link to something, like an event calendar, now i have everything all set up and done, but when it is the first day in the month that an event is on it messes up, otherwise it works perfect.

And sorry for how messy and crappy the code is : p

And knowing me its probly something dumb : p

Code: Select all

cal($_GET['month'],$_GET['year']);


function cal($month, $year){

	$firstday = date("l", mktime(0, 0, 0, $month, 1, $year));
	$firstdays = mktime(0,0,0, $month, 1, $year);
	$firstday_num = strftime("%d",$firstdays);
	global $lastday_num;
	$lastday = mktime(0, 0, 0, $month+1, 0, $year);
	$lastday_num = strftime("%d", $lastday);
	
	switch($month){
		case 1: 
			$month = "January";
		break;
		case 2:
			$month = "Feburary";
		break;
		case 3:
			$month = "March";
		break;
		case 4:
			$month = "April";
		break;
		case 5:
			$month = "May";
		break;
		case 6:
			$month = "June";
		break;
		case 7:
			$month = "July";
		break;
		case 8:
			$month = "August";
		break;
		case 9:
			$month = "September";
		break;
		case 10:
			$month = "October";
		break;
		case 11:
			$month = "November";
		break;
		case 12:
			$month = "Decmeber";
		break;
	}
	
	$wid = "0";
	
	$hei = "0";
	
	$pad = "2";
	
	$space = "1";
	
		print "\n <table border=\"0\" cellpadding=\"$pad\" cellspacing=\"$space\" width=\"\">
			<tbody>
			<tr>
			  <td height=\"5\" colspan=\"7\" align=\"center\" valign=\"center\">$month</td>
			  </tr>
			  <tr>
				<td align=\"center\" height=\"6\" valign=\"center\">Sun</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Mon</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Tues</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Wed</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Thur</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Fri</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Sat</td>
			  </tr>
			  ";
			  
	switch($firstday){
		case "Sunday":
			$week = 1;
		break;
		case "Monday":
			$week = 2;
		break;
		case "Tuesday":
			$week = 3;
		break;
		case "Wednesday":
			$week = 4;
		break;
		case "Thursday":
			$week = 5;
		break;
		case "Friday":
			$week = 6;
		break;
		case "Saturday":
			$week = 7;
		break;
	}
	
	print "\n <tr>";
	
	global $day;
	$day = 1;
	
	print "\n </tr><tr>";
	
	$i = 1;
	global $i;
	
	$rows=1;
	
	global $num;
	$num = 1;
	
	// Sets the events
	$tour = array();
	$tour[1] = "1";
	
	while($day<=$lastday_num){
		if($rows>7){
			$rows=0;
			$day=$day-1;
			print "\n </tr><tr>";
		}else{
		// Checks and sees if there is an event for this day
			if(isset($tour[$day])){
				print "\n <td width=\"$wid\" height=\"$hei\" align=\"center\" valign=\"center\" bgcolor=\"#0000FF\">$day</td>";
			}else{
				if($week>$num){
					print "\n <td width=\"$wid\" height=\"$hei\" align=\"center\" valign=\"center\">&nbsp;</td>";
					$day=0;
				}else{
					print "\n <td width=\"$wid\" height=\"$hei\" align=\"center\" valign=\"center\">$day</td>";
				}
			}
					
		}
		$num++;
		$day++;
		$rows++;
	}
	
			  print "\n </tr></table>";
}
Image

-NSF
Last edited by Zoxive on Sat Jan 28, 2006 2:40 pm, edited 1 time in total.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Sorry guys, never mind, i got it : p

Code: Select all

cal($_GET['month'],$_GET['year']);

function cal($month, $year){

	$firstday = date("l", mktime(0, 0, 0, $month, 1, $year));
	$firstdays = mktime(0,0,0, $month, 1, $year);
	$firstday_num = strftime("%d",$firstdays);
	global $lastday_num;
	$lastday = mktime(0, 0, 0, $month+1, 0, $year);
	$lastday_num = strftime("%d", $lastday);
	
	switch($month){
		case 1: 
			$month = "January";
		break;
		case 2:
			$month = "Feburary";
		break;
		case 3:
			$month = "March";
		break;
		case 4:
			$month = "April";
		break;
		case 5:
			$month = "May";
		break;
		case 6:
			$month = "June";
		break;
		case 7:
			$month = "July";
		break;
		case 8:
			$month = "August";
		break;
		case 9:
			$month = "September";
		break;
		case 10:
			$month = "October";
		break;
		case 11:
			$month = "November";
		break;
		case 12:
			$month = "Decmeber";
		break;
	}
	
	$wid = "0";
	
	$hei = "0";
	
	$pad = "2";
	
	$space = "1";
	
		print "\n <table border=\"0\" cellpadding=\"$pad\" cellspacing=\"$space\" width=\"\">
			<tbody>
			<tr>
			  <td height=\"5\" colspan=\"7\" align=\"center\" valign=\"center\">$month</td>
			  </tr>
			  <tr>
				<td align=\"center\" height=\"6\" valign=\"center\">Sun</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Mon</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Tues</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Wed</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Thur</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Fri</td>
				<td width=\"$wid\" height=\"6\" align=\"center\" valign=\"center\">Sat</td>
			  </tr>
			  ";
			  
	switch($firstday){
		case "Sunday":
			$week = 1;
		break;
		case "Monday":
			$week = 2;
		break;
		case "Tuesday":
			$week = 3;
		break;
		case "Wednesday":
			$week = 4;
		break;
		case "Thursday":
			$week = 5;
		break;
		case "Friday":
			$week = 6;
		break;
		case "Saturday":
			$week = 7;
		break;
	}
	
	print "\n <tr>";
	
	global $day;
	$day = 1;
	
	print "\n </tr><tr>";
	
	$i = 1;
	global $i;
	
	$rows=1;
	
	global $num;
	$num = 1;
	
	// Sets the events
	$tour = array();
	$tour[1] = "1";
	
	while($day<=$lastday_num){
		if($rows>7){
			$rows=1;
			//$day=$day-1;
			print "\n </tr><tr>";
		}else{
			if($week>$num){
				print "\n <td width=\"$wid\" height=\"$hei\" align=\"center\" valign=\"center\">&nbsp;</td>";
				$day = 0;
			}else{
			// Checks and sees if there is an event for this day
				if(isset($tour[$day])){
				print "\n <td width=\"$wid\" height=\"$hei\" align=\"center\" valign=\"center\" bgcolor=\"#0000FF\">$day</td>";
				}else{
				print "\n <td width=\"$wid\" height=\"$hei\" align=\"center\" valign=\"center\">$day</td>";
				}
			
			}
		$num++;
		$day++;
		$rows++;
		}
	}
	
			  print "\n </tr></table>";
}
-NSF
Post Reply