Hello, I have a calendar that I want to integrate into my website , but I want a button so the user can change the months. What line should I add ? I have the following code : <?php $date =time (); $day = date('d', $date); $month = date('m', $date); $year = date('Y', $date); $first_day = mktime(0,0,0,$month, 1, $year); $title = date('F', $first_day); $day_of_week = date('D', $first_day); switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year); echo "<table border=0 align=center id=calendar>"; echo "<tr><th colspan=7> $title $year </th></tr>"; echo "<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td></tr>"; $day_count = 1; echo "<tr>"; while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } $day_num = 1; while ($day_num <= $days_in_month) { if($day_num == $day) { echo "<td class=today>$day_num</td>"; } else { echo "<td class=days>$day_num</td>"; } $day_num++; $day_count++; if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } while ($day_count >1 && $day_count <=7) { echo "<td> </td>"; $day_count++; } echo "</tr></table>"; ?> Code (markup):
Here's what I came up with: <?php $date = (!isset($_GET['date'])) ? time() : $_GET['date']; $day = date('d', $date); $month = date('m', $date); $year = date('Y', $date); $first_day = mktime(0,0,0,$month, 1, $year); $title = date('F', $first_day); $day_of_week = date('D', $first_day); switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year); $before_m = strtotime("-1 month", $first_day); $after_m = strtotime("+1 month", $first_day); echo "<table border=0 align=center id=calendar>"; echo "<tr><th colspan=7> <!-- Prev month --> <form method=\"GET\" style=\"display:inline;\"> <input type=\"hidden\" name=\"date\" value=\"$before_m\" /> <input type=\"submit\" value=\"<-\" /> </form> $title $year <!-- Next MONTH --> <form method=\"GET\" style=\"display:inline;\"> <input type=\"hidden\" name=\"date\" value=\"$after_m\" /> <input type=\"submit\" value=\"->\" /> </form> </th></tr>"; echo "<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td></tr>"; $day_count = 1; echo "<tr>"; while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } $day_num = 1; while ($day_num <= $days_in_month) { if($day_num == $day) { echo "<td class=today>$day_num</td>"; } else { echo "<td class=days>$day_num</td>"; } $day_num++; $day_count++; if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } while ($day_count >1 && $day_count <=7) { echo "<td> </td>"; $day_count++; } echo "</tr></table>"; ?> PHP:
It;s great , but I also need the week number in front , can you help me with that ? Thank you very much.
Care to elaborate? http://php.net/manual/en/function.date.php Can help you with a lot. if you want to echo the week number, you can set at the top next to month/year $week = date('W', $date); and then echo $week whereever you want.
I just can't seem to make it work , I've set $day = date('d', $date); $month = date('m', $date); $week = date('W', $date); $year = date('Y', $date); and now i can make it work , i wnt to week number to be displayed in front of the days ...