kb9yjg Posted May 10, 2008 Share Posted May 10, 2008 Hello all, I have followed a tutorial to create a basic calendar and that portion works great! I had gone on to find a way to increment and decrement the months. This is the part that isnt working. All I have done for the script is add the buttons in and echo opening and closing form tags. Below echoing the calendar I have two if statements that state if the prev button is pressed then decrement the month by one and visa versa for the next button. Can anyone offer a suggestion as to what I am doing wrong and how to fix this problem? Thanks in advance. <? $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 align=center border=1 width=50%>"; echo "<form name=newmonth method=post action=#>"; echo "<tr><td align=center colspan=7><input type=submit name=prev value=Previous> ".$title." ".$year." <input type=submit name=next value=Next></td></tr>"; echo "</form>"; echo "<tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></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){ echo "<td align=center>".$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>"; echo "</table>"; if(isset($_POST['prev'])){ $title=date("F", mktime(0,0,0,date("m")-1,$day,$year),$first_day); }else{ $title=date("F", $first_day); } if(isset($_POST['next'])){ $title=date("F", mktime(0,0,0,date("m")+1,$day,$year),$first_day); }else{ $title=date("F", $first_day); } ?> Link to comment https://forums.phpfreaks.com/topic/104983-solved-next-and-previous-buttons-for-a-calendar/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.