clivehenderson
IS-IT--Management
Hi
Hope someone can help
I'm following a calendar tutorial which goes wrong when I add a loop. I think I'm missing a bracket but cannot work it out any A trained eye will probably spot it straight away I've spent ages and have got nowhere.
Any help appreciated
Clive
while ($currentDay <= $noDays) {
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
$calendar .= "</tr><tr>";
}
$calendar .= "</table>";
}
Code below
code]
function build_calendar($month,$year,$day) {
$daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
$noDays = date('t',$firstDayOfMonth);
$dateComponents = getdate($firstDayOfMonth);
$dayOfWeek = $dateComponents['wday'];
$monthName = date('F',mktime(0,0,0,$month,1,$year));
if($month == 1) {
$mn=12;
$yn=$year-1;
}
else {
$mn=$month-1;
$yn=$year;
}
if($month == 12) {
$mn2=1;
$yn2=$year+1;
}
else {
$mn2=$month+1;
$yn2=$year;
}
$calendar = "<table>";
$calendar .= "<tr><td><a href=day.php?m=$mn&y=$yn&d=$day><</a></td>";
$calendar .="<td colspan=5 align=center>$monthName, $year</td>";
$calendar .="<td><a href=day.php?m=$mn2&y=$yn2&d=$day>></a></td></tr>";
$calendar .="<tr>";
foreach($daysOfWeek as $day) {
$calendar .= "<td>$day</td>";
$calendar .= "</tr>";
$calendar .= "<tr>";
$currentDay = 1;
if ($dayOfWeek > 0) {
$calendar .= "<td colspan='$dayOfWeek'> </td>";
}
/*
Generate the days of the month recursively.
The $currentDay variable will be iterated until it equals the number of days of the specified month. Also, the $dayOfWeek variable can only take values between 0 and 6. When it reaches 7, it means you have reached the end of the row and the variable will be reset to 0 to mark the beginning of a new week.
*/
while ($currentDay <= $noDays) {
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
$calendar .= "</tr><tr>";
}
$calendar .= "</table>";
}
return $calendar;
code]
Hope someone can help
I'm following a calendar tutorial which goes wrong when I add a loop. I think I'm missing a bracket but cannot work it out any A trained eye will probably spot it straight away I've spent ages and have got nowhere.
Any help appreciated
Clive
while ($currentDay <= $noDays) {
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
$calendar .= "</tr><tr>";
}
$calendar .= "</table>";
}
Code below
code]
function build_calendar($month,$year,$day) {
$daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
$noDays = date('t',$firstDayOfMonth);
$dateComponents = getdate($firstDayOfMonth);
$dayOfWeek = $dateComponents['wday'];
$monthName = date('F',mktime(0,0,0,$month,1,$year));
if($month == 1) {
$mn=12;
$yn=$year-1;
}
else {
$mn=$month-1;
$yn=$year;
}
if($month == 12) {
$mn2=1;
$yn2=$year+1;
}
else {
$mn2=$month+1;
$yn2=$year;
}
$calendar = "<table>";
$calendar .= "<tr><td><a href=day.php?m=$mn&y=$yn&d=$day><</a></td>";
$calendar .="<td colspan=5 align=center>$monthName, $year</td>";
$calendar .="<td><a href=day.php?m=$mn2&y=$yn2&d=$day>></a></td></tr>";
$calendar .="<tr>";
foreach($daysOfWeek as $day) {
$calendar .= "<td>$day</td>";
$calendar .= "</tr>";
$calendar .= "<tr>";
$currentDay = 1;
if ($dayOfWeek > 0) {
$calendar .= "<td colspan='$dayOfWeek'> </td>";
}
/*
Generate the days of the month recursively.
The $currentDay variable will be iterated until it equals the number of days of the specified month. Also, the $dayOfWeek variable can only take values between 0 and 6. When it reaches 7, it means you have reached the end of the row and the variable will be reset to 0 to mark the beginning of a new week.
*/
while ($currentDay <= $noDays) {
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
$calendar .= "</tr><tr>";
}
$calendar .= "</table>";
}
return $calendar;
code]