Page 1 of 1

Dynamic Calendar

Posted: Fri Nov 04, 2005 1:47 pm
by siefkencp
Im working on a dynamic calendar to display weekdays... The problem is that it always prints the first day of the week on monday even if it starts on friday. It leaves blank spaces correctly they should simply be inserted before the display starts and not after.

Obviously because of my display logic, I have been racking my brain all day to solve the problem and thought I'd toss it on here for some suggestions. I have tried various indexing methods with no luck but that does not mean it can't be done with indexing.

Thanks for your help.

Chris

Code: Select all

$today = date("m/d/y");
$table = "<table border=\"1\" cellpadding=\"4\">\n";

$start_date = getdate(mktime(0,0,0,$month,1,$year));
$end_date = getdate(mktime(0,0,0,$month+1,0,$year));

$i = $start_date['mday'];
$end_mday = $end_date['mday'];
$long_month = $start_date['month'];
print $long_month . "<br>\n";
$table .= "
<tr>\n 
<td>Mon</td>\n
<td>Tue</td>\n
<td>Wed</td>\n
<td>Thur</td>\n
<td>Fri</td>\n
</tr>\n";

while($i != $end_mday){
	
	$work_date = getdate(mktime(0,0,0,$month,$i,$year));
	$w = $work_date['wday'];

	if($w == '0'){
		$table .= "<tr>\n";
	}

	if(($w != '0') and ($w != '6')){
	$table .= "<td>$i<br>\n";
	}
	

	if($w == '6'){
		$table .= "</tr>\n";
	}
	$i++;
}

$table .= "</table>\n";

print $table;

Re: Dynamic Calendar

Posted: Fri Nov 04, 2005 2:12 pm
by Burrito
siefkencp wrote:The problem is that it always prints the first day of the week on monday even if it starts on friday.
what do you mean by that? You're only printing out the weekdays...don't weekdays always start on Monday? 8O

w/o fully understanding what you're trying to do, the best thing I can say is to make sure that you pad the days correctly for each week.

do you have a sample so I can see and better understand what your problem is?

Posted: Fri Nov 04, 2005 2:17 pm
by siefkencp
I get this...

Mon Tue Wed Thur Fri
1 2
5 6 7 8 9
12 13 14 15 16
19 20 21 22 23
26 27 28 29

When I want:

Mon Tue Wed Thur Fri
X X X 1 2
5 6 7 8 9
12 13 14 15 16
19 20 21 22 23
26 27 28 29

:)

Posted: Fri Nov 04, 2005 2:23 pm
by Burrito
umm....those look the same to me.

I assume you mean this:

Code: Select all

Mon Tue Wed Thur Fri 
              1   2 
  5   6   7   8   9 
 12   13  14  15  16 
 19   20  21  22  23 
 26   27  28  29
if that's the case, then do as I suggested and make sure you pad the calendar for days prior to the start of the month

search for a post of mine in the snippets forum that has a calendar in it. It will serve as a good example of how to pad the first week.

Posted: Fri Nov 04, 2005 2:49 pm
by siefkencp
your right... searching now.