Hi
I have a calendar code that isn't returning the 1st sunday onto the next line if it isn't the first day of the month can anyone help the code is as follows.
I have a calendar code that isn't returning the 1st sunday onto the next line if it isn't the first day of the month can anyone help the code is as follows.
| Code: |
| <?php
//Set calendar info $currentDay = date('d'); $currentMonth = date('m'); $currentYear = date('Y'); $currentDayName = date('l'); $currentDayS = date('dS'); $currentMonthName = date('F'); //Get the number of days in current month $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $currentMonth, $currentYear); //Get offset of 1st day $firstDayOfMonth = date('w', mktime(0, 0, 0, $currentMonth, 1, $currentYear)); //Set the names of the days in the week $days = array(); $days[] = "Sunday"; $days[] = "Monday"; $days[] = "Tuesday"; $days[] = "Wednesday"; $days[] = "Thursday"; $days[] = "Friday"; $days[] = "Saturday"; //Display all the day names $dayName = ""; foreach($days as $x => $y) { $dayName .= "<td align='center' bgcolor='#999999' width='14.28%' >".$y." </td>"; } //Spacers for the offset for the 1st day of the month $weekDays = ""; $i = $fisrtDayOfMonth + 1; if($firstDayOfMonth != "0") { $weekDays .= "<td colspan='".$firstDayOfMonth."'> </td>"; } //Set default first day to 1 $iDay = 1; $ii = $i; $amountOfDays = $daysInMonth + $firstDayOfMonth; for($i; $i <= $amountOfDays; $i++) { //$i decides what the row colour will be if($i % 2) { $color = '#ffaaff'; } else { $color = '#ffffaa'; } //If the current day is sunday, make sure a new row starts if($ii == 8) { $weekDays .= "</tr><tr>"; $ii = 1; } //Highlight the current day if($currentDay == $iDay) { $extra = 'bgcolor="#ff0000"'; } else { $extra = 'bgcolor="#'.$color.'"'; } //Show the days $weekDays .= "<td height='65' valign='top' ". $extra .">". $iDay ."</td>"; //increment the day and week number (ii) $iDay++; $ii++; } //Add end month spacers if((8 - $ii) >= "1") { $weekDays .= "<td colspan='". (8-$ii) ."'></td>"; } ?> <html> <style type="text/css"> table,tr,td,th,tbody,TR,TD { font-family: Verdana; font-size: 8pt; font-size: 11; color: #000000; border-font-size: 11; color: #000000; border-collapse: collapse; } </style> <table border="1" cellpadding="1" cellspacing="1" width="98%"> <tr> <td align="center" colspan="7" bgcolor="#999999"> <?php echo $currentDayName ." the ". $currentDayS ." of ". $currentMonth .", ". $currentYear; ?> </td> </tr> <tr> <?php echo $dayName; ?> </tr> <tr> <?php echo $weekDays; ?> </tr> </table> </html> |
