Jump to content

PHP Scheduler/Calender - Take 2!


Go to solution Solved by Barand,

Recommended Posts

Hi guys, i'm back with more calender/scheduler woes! Off the back of some very helpful guidance on this forum i resolved the layout issues i was havving dealing with the start of the month (topic: https://forums.phpfreaks.com/topic/306821-php-schedulercalender/).

 

However, now im having problems with the display on two of the 12 months and i cant understand why its happening. If you look at the demo here: http://sgindustries.co.uk/test/test.php?v=month&m=3&y=2018 you can see it displays perfectly for all months apart from April and July when the layout is all screwed up!

 

The only similarities between these months i can see is their first day is a Sunday but why should that balls up the layout so badly?

 

the functionallitly of the thing is still there just its all over the shop on those two months. Any help/suggestions would be greatly appreciated!

 

Code for the calendar/scheduler;

<?php

# calNavigation #
$calMonth=$_GET['m'];
$calYear=$_GET['y'];
$prevMonth=$calMonth-1;
$nextMonth=$calMonth+1;
#################

$month=gmdate("m");	// Find today's month
$day=gmdate("d");     // Finds today's date
$year=gmdate("Y");     // Finds today's year

$no_of_days=gmdate('t',gmmktime(0,0,0,$calMonth,1,$calYear)); // This is to calculate number of days in a month
$mn=gmdate('F',gmmktime(0,0,0,$calMonth,1,$calYear)); // Month is calculated to display at the top of the calendar
$yn=gmdate('Y',gmmktime(0,0,0,$calMonth,1,$calYear)); // Year is calculated to display at the top of the calendar
$j=gmdate('N',gmmktime(0,0,0,$calMonth,1,$calYear)); // This will calculate the week day of the first day of the month

/// top line showing name of the days of the week
echo"<table class='calTable' align='center' valign='top' border='0' cellpadding='5' cellspacing='2'>\n"
."<tr>\n<td align='center' valign='middle' colspan='7' class='calTitle'><span class='prevMonth'><a href='./test.php?v=month&m=$prevMonth&y=$calYear' title='View last months schedule'><< Prev</a></span><span>".$mn." ".$yn."</span><span class='nextMonth'><a href='./test.php?v=month&m=$nextMonth&y=$calYear' title='View next months schedule'>Next >></a></span></td>\n</tr>\n"
."<tr>\n<td colspan='7' height='5'></td>\n</tr>\n"
."<tr>\n<td align='center' valign='middle'><b>Sun</b></td>\n<td align='center' valign='middle'><b>Mon</b></td>\n<td align='center' valign='middle'><b>Tue</b></td>\n<td align='center' valign='middle'><b>Wed</b></td>\n<td align='center' valign='middle'><b>Thu</b></td>\n<td align='center' valign='middle'><b>Fri</b></td>\n<td align='center' valign='middle'><b>Sat</b></td>\n</tr>\n"
."<tr>\n<td colspan='7' height='5'></td>\n</tr>\n"
////// End of the top line showing name of the days of the week//////////

."<tr>\n";

for($k=0, $adj=''; $k<$j; $k++){ $adj .= "<td width='117' height='117' align='left' valign='top'></td>\n"; }

for($i=1;$i<=$no_of_days;$i++){
	
	if($i<10){$i="0".$i."";}
	
		$getevent_sql=@mysql_query("SELECT * FROM schedule WHERE date>='".gmmktime(0,0,0,$calMonth,$i,$calYear)."' AND date<='".gmmktime(23,59,59,$calMonth,$i,$calYear)."' ORDER BY date ASC, title ASC");
		$getevent_num=@mysql_num_rows($getevent_sql);
		$getevent_sql=@mysql_query("SELECT * FROM schedule WHERE date>='".gmmktime(0,0,0,$calMonth,$i,$calYear)."' AND date<='".gmmktime(23,59,59,$calMonth,$i,$calYear)."' ORDER BY date ASC, title ASC LIMIT 0,2");
		$calendardisplay_num=$getevent_num;
			
		echo "$adj<td width='117' height='117' align='left' valign='top' class='calday'><i><a href='./test.php?v=day&d=$i&m=$month&y=$year'>$i</a></i><br />";
		while($eventinfo=@mysql_fetch_array($getevent_sql)) {
			$id=$eventinfo['id'];
			$title=$eventinfo['title'];
		
			echo"<a href='./test.php?view=event&id=$id' title='".$title."'>";
			if (strlen(substr("".str_replace("’", "'", "".$title."")."", 0,12))>=12) { echo"".substr("".str_replace("’", "'", "".$title."")."", 0,12)."..."; } else { echo"".str_replace("’", "'", "".$title."").""; }
			echo"</a><br />";
		}

	if($calendardisplay_num>2) { echo"<a href='./test.php?v=day&d=$i&m=$month&=$year'><i><font class='smalltext'>...more</font></i></a>"; }
	
	echo"</td>\n"; // This will display the date inside the calendar cell
	$adj='';
	$j++;
	if($j==7){
		echo"</tr>\n";
		$j=0;
	}
}

echo"<tr>\n<td height='3' colspan='7'></td>\n</tr>\n</table>\n";

?>
Link to comment
https://forums.phpfreaks.com/topic/306888-php-schedulercalender-take-2/
Share on other sites

for($k=0, $adj=''; $k<$j; $k++){

1. $j depends on gmdate's 'N' formatting character. What kinds of values does it produce?

A: $j outputs a number 0-6 for the start day, sunday being 0. it currently outputs 4 as the start of March was a Thursday

2. How does that affect what $k will do?

A: If $k is initialised to 0, and then incremmented by one each time round the for loop until its equal to the start day ($j) then shouldn't it just start the table creation instead of putting in the $adj cell?

Edited by benhullah
  • Solution

 

1. $j depends on gmdate's 'N' formatting character. What kinds of values does it produce?

A: $j outputs a number 0-6 for the start day, sunday being 0. it currently outputs 4 as the start of March was a Thursday

 

I think you should re-read the manual

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.