justinh Posted October 30, 2008 Share Posted October 30, 2008 I want to add a backward and forward button to cycle through the months.. how would i go about this? <?php $date = time(); $day = date('d',$date); $month = date('m',$date); $year = date('y',$date); $firstday = mktime(0,0,0, $month, 1, $year); $title = date('F', $firstday); $dayofweek = date('D', $firstday); switch($dayofweek){ 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; } $daysinmonth = cal_days_in_month(0, $month, $year); echo "<table border=1 width=294>"; echo "<tr><th colspan=7>$month - $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>"; $daycount = 1; echo "<tr>"; while ($blank > 0){ echo "<td></td>"; $blank = $blank-1; $daycount++; } $daynum = 1; while($daynum <= $daysinmonth){ if ($daynum == $day){ $processid = $month.$daynum.$year; echo "<td><font color=red><a href=\"process.php?date=$processid\"> $daynum</a> </font></td>"; $daynum++; $daycount++; } else { echo "<td> <a href=\"process.php?date=$processid\">$daynum</a> </td>"; $daynum++; $daycount++; if($daycount > 7){ echo "</tr><tr>"; $daycount = 1; } } } while($daycount >= 1 && $daycount < 7){ echo "<td></td>"; $daycount++; } echo "</tr></table>"; ?> Link to comment https://forums.phpfreaks.com/topic/130768-calender-question/ Share on other sites More sharing options...
justinh Posted October 30, 2008 Author Share Posted October 30, 2008 well i am trying to make a forward and backward arrow to cycle threw the months, but im a little new to php i wrote this function but nothing happens when i click on the arrows. thanks in advance! <?php function nav($month){ if (!isset($_GET['direction'])){ } else { if($_GET['direction'] = forward){ $month++; } else { $month--; }}} $date = time(); $day = date('d',$date); $month = date('m',$date); nav($month); $year = date('y',$date); $firstday = mktime(0,0,0, $month, 1, $year); $title = date('F', $firstday); $dayofweek = date('D', $firstday); switch($dayofweek){ 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; } $daysinmonth = cal_days_in_month(0, $month, $year); echo "<table border=1 width=294>"; echo "<tr><th colspan=7><a href=\"calender.php?direction=backward\"><</a> $month - $year <a href=\"calender.php?direction=forward\">></a></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>"; $daycount = 1; echo "<tr>"; while ($blank > 0){ echo "<td></td>"; $blank = $blank-1; $daycount++; } $daynum = 1; while($daynum <= $daysinmonth){ $processid = $month.$daynum.$year; if ($daynum == $day){ echo "<td><font color=red><a href=\"process.php?date=$processid\"> $daynum</a> </font></td>"; $daynum++; $daycount++; } else { echo "<td> <a href=\"process.php?date=$processid\">$daynum</a> </td>"; $daynum++; $daycount++; if($daycount > 7){ echo "</tr><tr>"; $daycount = 1; } } } while($daycount >= 1 && $daycount < 7){ echo "<td></td>"; $daycount++; } echo "</tr></table>"; ?> Link to comment https://forums.phpfreaks.com/topic/130768-calender-question/#findComment-678701 Share on other sites More sharing options...
justinh Posted October 30, 2008 Author Share Posted October 30, 2008 any ideas? Link to comment https://forums.phpfreaks.com/topic/130768-calender-question/#findComment-678713 Share on other sites More sharing options...
Barand Posted October 30, 2008 Share Posted October 30, 2008 there's an example in here http://www.phpfreaks.com/forums/index.php/topic,110884.msg448961.html#msg448961 Link to comment https://forums.phpfreaks.com/topic/130768-calender-question/#findComment-678726 Share on other sites More sharing options...
justinh Posted October 30, 2008 Author Share Posted October 30, 2008 Thanks for your reply. I really don't understand any of that code and which part applies to my problem. I am still a beginner in PHP, but I really don't like to just copy and paste a code in and see if it fixes my problem. I did however make a step in the right direction i think with this function i made. function is at the top <?php function NavigateCalender($month){ if (isset($_GET['direction'])){ switch($_GET['direction']){ case "1": $month--; global $month = $month; echo $month; break; case "2": $month++; echo $month; break; } } else { } } $date = time(); $day = date('d',$date); $month = date('m',$date); $year = date('y',$date); $firstday = mktime(0,0,0, $month, 1, $year); $title = date('F', $firstday); $dayofweek = date('D', $firstday); NavigateCalender($month); switch($dayofweek){ 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; } $daysinmonth = cal_days_in_month(0, $month, $year); echo "<table border=1 width=294>"; echo "<tr><th colspan=7><a href=\"calender.php?direction=1\"><</a> $month - $year <a href=\"calender.php?direction=2\">></a></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>"; $daycount = 1; echo "<tr>"; while ($blank > 0){ echo "<td></td>"; $blank = $blank-1; $daycount++; } $daynum = 1; while($daynum <= $daysinmonth){ $processid = $month.$daynum.$year; if ($daynum == $day){ echo "<td><font color=red><a href=\"process.php?date=$processid\"> $daynum</a> </font></td>"; $daynum++; $daycount++; } else { echo "<td> <a href=\"process.php?date=$processid\">$daynum</a> </td>"; $daynum++; $daycount++; if($daycount > 7){ echo "</tr><tr>"; $daycount = 1; } } } while($daycount >= 1 && $daycount < 7){ echo "<td></td>"; $daycount++; } echo "</tr></table>"; ?> When I click on the arrow it echo's either 9 ( backward arrow ) or 11 (forward arrow) // i used this for debugging But it still doesn't update the calender with the new month. Also it only echo's the next month once. Thanks in advance for the help Justin Link to comment https://forums.phpfreaks.com/topic/130768-calender-question/#findComment-678775 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.