I have made the following script to print out a calendar when a month and year are specified. It nearly works except it prints out an anomolous 1.
Here is the script:
function parseCalendar($month,$year,$dateinfo) {
// Take Function Inputs and make a Timestamp
$ts = mktime(0,0,0,$month,1,$year);
// Get info about timestamp
$tsinfo = getdate($ts);
// Set counting variables to 0
$x = 0;
$colcount = 0;
// Open the table
echo "<TABLE BORDER=1><TR><TD CLASS=\"day-header\">Sun</TD><TD CLASS=\"day-header\">Mon</TD><TD CLASS=\"day-header\">Tue</TD><TD CLASS=\"day-header\">Wed</TD><TD CLASS=\"day-header\">Thu</TD><TD CLASS=\"day-header\">Fri</TD><TD CLASS=\"day-header\">Sat</TD></TR>";
echo "<TR>";
// While Count is less than or equal to no. of days in month
while($x <= date("t",$ts)) {
// If count is 0 work along columns until correct day is found
if($x == 0) {
while ($colcount < 7) {
// If 7 cells wide start a new row
if($colcount == 6) {
echo "</tr><tr>\n";
$colcount = 0;
}
if($colcount == $tsinfo['wday']){
// If the correct column is reached print 1st day
echo "<td>" . $x + 1 . "</td>";
break;
} else {
// If false print empty cell
print("<TD>-</TD>");
$colcount++;
}
}
} else {
// Start printing other days
// If $dateinfo exists (linked-days)
if($dateinfo) {
eval($dateinfo);
echo "<TD onMouseover=\"javascript:showInfo('$code');\"><A HREF=\"{$link}\" CLASS=\"date-link\">{$x}}</A></TD>";
} else {
// Print out a plain old day
echo "<td>" . $x . "</td>";
}
$colcount++;
if($colcount == 7) {
echo "</tr><tr>\n";
$colcount = 0;
}
}
$x++;
}
}
I know the problem is at
echo "<td>" . $x + 1 . "</td>";
because if I substitute 1 with another number that appears in the place of the anamolous 1. If I take the + 1 away then the first row of numbers goes funny. Any ideas?
I know that there are loads of calendar scripts on offer, but some required mySQL(which is not available) and some don't allow easy customization, eg. allow a date to be a link to a certain page. None also allowed me to change the <A> tag to add a mouseover for linked days.