been looking at this for a bit and now my eyes are crossed. 🙂
I have a calendar script that I found on snipplr.com It’s pretty sweet. Props to the creators. Now, I have two things I want to customize.
Right now, the calendar spits out 12 months, January to December. And also the week ends on Sunday (grrrr). I am attempting to make it go from THIS MONTH, plus x number of months. For example, it would display December, plus 5 more months, so Dec, Jan, Feb, March, April, May.
I can tell in the code it uses a $i iteration to get through the months and display the appropriate dates. for($i=1;$i<=11;$i++)
SO, I tried changint it to this: for($i=$this_month;$i<=11;$i++)
$this_month of course being the date(‘m’);
It does successfully display December, but no months after it. (Since it stops at 11). But if I up the 11 to another variable of $this_month+5, then the script doesnt know what months 13, 14 and 15 are.
Any help on this one? Here is the entire script I have thusfar.
function days_in_month($month, $year) {
if($month!=2) {
if($month==9||$month==4||$month==6||$month==11)
return 30;
else
return 31;
}
else
return $year%4==""&&$year%100!="" ? 29 : 28;
}
global $months;
$months = array(0 => 'January', 1 => 'February', 2 => 'March', 3 => 'April', 4 => 'May', 5 => 'June', 6 => 'July', 7 => 'August', 8 => 'September', 9 => 'October', 10 => 'November', 11 => 'December');
$days = array(0 => 'Monday', 1 => 'Tuesday', 2 => 'Wednesday', 3 => 'Thursday', 4 => 'Friday', 5 => 'Saturday', 6 => 'Sunday');
function render_calendar($this_year = null) {
if($this_year==null)
$this_month = date('m')-1;
$first = strtotime(date('m'));
$last = strtotime("+6 months", $this_month);
$this_year = date('Y');
$day_of_the_month = date('N', strtotime('1 January '.$this_year));
for($i=$this_month;$i<=12;$i++) {
// echo $i;
// if ($i==12) {
// $i = 0;
// }
echo $i;
echo "<table>
<caption>".$GLOBALS['months'][$i]."</caption>
<thead>
<tr>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
</thead>
<tbody>
<tr>";
for($n=1;$n<$day_of_the_month;$n++)
echo "<td></td>\n";
$days = days_in_month($i+1, $this_year);
$day = 0;
while($day<$days) {
if($day_of_the_month==8) {
echo ($day == 0 ? "" : "</tr>\n") . "<tr>\n";
$day_of_the_month = 1;
}
echo "<td style=\"border: 1px solid red;\">" . ($day+1) . "</td>\n";
$day_of_the_month++;
$day++;
}
echo "</tr>
</tbody>
</table>";
}
}
How about this for your loop: