Hjælp til kalender linjeskift
Hej Eksperter. Jeg er ved at lave et kalenderscript, som jeg har lavet det nu brækker den ugen efter 7 dage- problemet er hvis en måned så starter f.eks. en torsdag.. så bliver opstillingen pludselig mærkelig :SHvorledes kan jeg gøre det hvis jeg vil have den til at brække hver søndag istedet?
<?php
$date = time();
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
//generate first day of the month
$first_day = mktime(0,0,0,$month, 1, $year);
//this gets us the month name
$title = date('F', $first_day);
//here we find out what day of the week the first day of the month falls on
$day_of_week = date('D', $first_day);
switch($day_of_week) {
case "Mon": $blank = 0; break;
case "Tue": $blank = 1; break;
case "Wed": $blank = 2; break;
case "Thu": $blank = 3; break;
case "Fri": $blank = 4; break;
case "Sat": $blank = 5; break;
case "Sun": $blank = 6; break;
}
//determine how many days in current month
$days_in_month = cal_days_in_month(0, $month, $year);
//construct table heads
echo "<table border=1 width=294>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr><td width=42>M</td><td width=42>T</td><td width=42>O</td><td width=42>T</td><td width=42>F</td><td width=42>L</td><td width=42>S</td></tr>";
//This counts the days in the week, up to 7
$day_count = 1;
echo "<tr>";
//first we take care of those blank days
while ( $blank > 0 )
{
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}
$day_count = 1;
//COUNTING
//sets the first day of the month to 1
$day_num = 1;
//count up the days, untill we've done all of them in the month
while ( $day_num <= $days_in_month )
{
echo "<td> $day_num </td>";
$day_num++;
$day_count++;
//Make sure we start a new row every week
if ($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}
//Finaly we finish out the table with some blank details if needed
while ( $day_count >1 && $day_count <=7 )
{
echo "<td> </td>";
$day_count++;
}
echo "</tr></table>";
?>
