| [ASK] para master PHP mohon bantuannya lagi nih, ane dapet source code untuk buat kalendar php. Kalendar sih udah bisa muncul, tapi ketika ane tambahin script untuk previous dan next tidak running. Berikut source codenya
<html> <head> <script> function goLastMonth(month, year) { if(month == 1) { --year; month = 12; } document.location.href="<?php $_SERVER['PHP_SELF'];?>?month="+month"&year="+year"; } function goNextMonth(month, year) { if(month == 12) { ++year; month = 1; } document.location.href="<?php $_SERVER['PHP_SELF'];?>?month="+month"&year="+year"; } </script> </head> <body> <?php if(isset($_GET['day'])) { $day = $_GET['day']; } else { $day = date("j"); } if(isset($_GET['month'])) { $month = $_GET['month']; } else { $month = date("n"); } if(isset($_GET['year'])) { } else { $year = date("Y"); } //This code store day, month, and year variable in timeStamp $currentTimeStamp = strtotime("$year-$month-$day");
//Get current month name $monthName = date("F", $currentTimeStamp);
//Get how many days are there in current Month $numDays = date("t", $currentTimeStamp);
//We need to set variable to count cell in the loop later $counter = 0; ?> <table border=1> <tr> <td><input style='width:50px;' type='button' value='<' name='previousbutton' onclick="goLastMonth(<?php echo $month.", ".$year?>)"></td> <td colspan=5 align=center><?php echo $monthName.", ".$year; ?></td> <td><input style='width:50px;' type='button' value='>' name='nextbutton' onclick="goNextMonth(<?php echo $month.", ".$year?>)"></td> </tr> </tr> <td align=center width=200><b>Sun</b></td> <td align=center width=200><b>Mon</b></td> <td align=center width=200><b>Tue</b></td> <td align=center width=200><b>Wed</b></td> <td align=center width=200><b>Thu</b></td> <td align=center width=200><b>Fri</b></td> <td align=center width=200><b>Sat</b></td> </tr> <?php echo"<tr>"; for($i = 1; $i < $numDays+1; $i++, $counter++) { $timeStamp = strtotime("$year-$month-$i"); if($i == 1) { $firstDay = date("w", $timeStamp); for($j = 0; $j < $firstDay; $j++, $counter++) { //Blank Space echo"<td></td>"; } } if($counter % 7 == 0) { echo"</tr><tr>"; } echo"<td height=150 valign=top>".$i."</td>"; } echo"</tr>"; ?> </table> </body> </html>
buttonya tidak bisa berfungsi untuk menampilkan previous dan next month.
mohon di bantunya para master |
Tidak ada komentar:
Posting Komentar