Dynamic 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
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Dynamic Calendar

Post 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;
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Dynamic Calendar

Post 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?
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Post 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

:)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Post by siefkencp »

your right... searching now.
Post Reply