So recently I found a nifty little tutorial for making a calender using PHP and HTML. I used a lot of the code from the tutorial, since it saved me from doing all the math myself. Dates sure do suck. Anyway, the calender works just how I wanted it to, except for one tiny detail.
Between the buttons for navigating to the previous and next month and the current month name is a row of n’s. The navigation buttons and month names are both in their own tables, and there is no code between them. In Google Chrome, the n’s are in a big row, like this:
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
while in Internet Explorer, the n’s are in a column, with one n for each row. I’ve been going over the code for a while now and still cannot figure out where these are coming from or why. I’m new to using the date function in PHP, so I’m wondering if that has something to do with this.
Here’s the code in question;
<?php
include'../../includes/head.inc';
include'../../includes/secure.inc';
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<div class="calendar">
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="50%" align="left"> <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="5" cellspacing="5">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>n";
if($i < $startday) echo "<td></td>n";
else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td>n";
if(($i % 7) == 6 ) echo "</tr>n";
}
?>
</table>
</td>
</tr>
</table>
</div>
<?php
include'../../includes/footer.inc';
?>
The code is a bit sloppy since I was just trying to get it to work at the moment and am planning on doing all the formatting later. I need to get rid of these n’s first though.
Any help would be appreciated.
Towards the end of the code:
I’d say someone saw
\nat the end of each line and removed the\but not thenpart.