Dynamic Calendar
Posted: Fri Nov 04, 2005 1:47 pm
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
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;