matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 Hello, I am trying to figure out a way that I can avoid manually changing the code on my calender select option "year' every year, is it possible to set it to current year + 1? Cal.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <div align="center"> <?php if ((!isset($_GET["Month"])) && (!isset($_GET["Year"]))) { $Month = date("m"); $Year = date("Y"); } else { $Month = $_GET["Month"]; $Year = $_GET["Year"]; } $Timestamp = mktime(0,0,0,$Month,1,$Year); $MonthName = date("F", $Timestamp); ?> <?php echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\">"; echo "<tr><td colspan=\"7\" align=\"left\">Calendar Table for $MonthName, $Year</td></tr>"; echo "<tr bgcolor=\"#999999\">"; $daysOfWeek = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); foreach ($daysOfWeek as $value) { echo "<td align=\"center\"><strong><font color=\"#ffffff\">$value</font></strong></td>"; } echo "</tr>"; $MonthStart = date("w", $Timestamp); if ($MonthStart == 0) { // if the month starts on a Sunday $MonthStart = 7; } $LastDay = date("d", mktime(0,0,0,$Month+1, 0, $Year)); $StartDate = -$MonthStart; for ($k=1;$k<=6;$k++){ //print six rows for six possible weeks echo"<tr>"; for ($j=1;$j<=7;$j++){ //seven columns per row $StartDate++; if($StartDate < $LastDay) { //blank calendar space if($StartDate > 0) { echo"<td>$StartDate</td> \n"; } else { echo"<td bgcolor=\"#eeeeee\"></td> \n"; } } elseif (($StartDate <=1) && ($StartDate >= $LastDay)) { //date goes here if($StartDate >= 0) { echo"<td>$StartDate</td> \n"; } } } echo"</tr>"; } //End Table Row echo "</table>"; ?> <hr width="200"> <form action="cal.php" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="GET" > <?php echo "<select name=\"Month\">"; for($m=1;$m<=12;$m++){ $selected = ""; $longDate = date("F", mktime(0,0,0,$m,1,$Year)); if ($Month==$m){ $selected = "selected "; } echo "<option value=\"$m\" $selected>$longDate</option> \n"; } echo "</select>"; echo "<select name=\"Year\">"; for($y=2009;$y<=2010;$y++){ $selected = ""; $longDate = date("Y", mktime(0,0,0,1,1,$y)); if ($Year==$y){ $selected = "selected \n"; } echo "<option value=\"$y\" $selected>$longDate</option> \n"; } echo "</select>"; ?> <input type="submit" value="go"> </form> </div> </body> </html> Appreciate any help. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted March 19, 2009 Share Posted March 19, 2009 Line 83 $yeartoday = date(Y); $yearplus1 = date(Y)+1; for($y=yeartoday;$y<=$yearplus1;$y++){ Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Author Share Posted March 19, 2009 I have changed it to this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <div align="center"> <?php if ((!isset($_GET["Month"])) && (!isset($_GET["Year"]))) { $Month = date("m"); $Year = date("Y"); } else { $Month = $_GET["Month"]; $Year = $_GET["Year"]; } $Timestamp = mktime(0,0,0,$Month,1,$Year); $MonthName = date("F", $Timestamp); ?> <?php echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\">"; echo "<tr><td colspan=\"7\" align=\"left\">Calendar Table for $MonthName, $Year</td></tr>"; echo "<tr bgcolor=\"#999999\">"; $daysOfWeek = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); foreach ($daysOfWeek as $value) { echo "<td align=\"center\"><strong><font color=\"#ffffff\">$value</font></strong></td>"; } echo "</tr>"; $MonthStart = date("w", $Timestamp); if ($MonthStart == 0) { // if the month starts on a Sunday $MonthStart = 7; } $LastDay = date("d", mktime(0,0,0,$Month+1, 0, $Year)); $StartDate = -$MonthStart; for ($k=1;$k<=6;$k++){ //print six rows for six possible weeks echo"<tr>"; for ($j=1;$j<=7;$j++){ //seven columns per row $StartDate++; if($StartDate < $LastDay) { //blank calendar space if($StartDate > 0) { echo"<td>$StartDate</td> \n"; } else { echo"<td bgcolor=\"#eeeeee\"></td> \n"; } } elseif (($StartDate <=1) && ($StartDate >= $LastDay)) { //date goes here if($StartDate >= 0) { echo"<td>$StartDate</td> \n"; } } } echo"</tr>"; } //End Table Row echo "</table>"; ?> <hr width="200"> <form action="cal.php" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="GET" > <?php echo "<select name=\"Month\">"; for($m=1;$m<=12;$m++){ $selected = ""; $longDate = date("F", mktime(0,0,0,$m,1,$Year)); if ($Month==$m){ $selected = "selected "; } echo "<option value=\"$m\" $selected>$longDate</option> \n"; } echo "</select>"; echo "<select name=\"Year\">"; $yeartoday = date(Y); $yearplus1 = date(Y)+1; for($y=yeartoday;$y<=$yearplus1;$y++){ $selected = ""; $longDate = date("Y", mktime(0,0,0,1,1,$y)); if ($Year==$y){ $selected = "selected \n"; } echo "<option value=\"$y\" $selected>$longDate</option> \n"; } echo "</select>"; ?> <input type="submit" value="go"> </form> </div> </body> </html> But it just lists 2000, and repeats it infinitely ???? Quote Link to comment Share on other sites More sharing options...
Daney11 Posted March 19, 2009 Share Posted March 19, 2009 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <div align="center"> <?php if ((!isset($_GET["Month"])) && (!isset($_GET["Year"]))) { $Month = date("m"); $Year = date("Y"); } else { $Month = $_GET["Month"]; $Year = $_GET["Year"]; } $Timestamp = mktime(0,0,0,$Month,1,$Year); $MonthName = date("F", $Timestamp); ?> <?php echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\">"; echo "<tr><td colspan=\"7\" align=\"left\">Calendar Table for $MonthName, $Year</td></tr>"; echo "<tr bgcolor=\"#999999\">"; $daysOfWeek = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); foreach ($daysOfWeek as $value) { echo "<td align=\"center\"><strong><font color=\"#ffffff\">$value</font></strong></td>"; } echo "</tr>"; $MonthStart = date("w", $Timestamp); if ($MonthStart == 0) { // if the month starts on a Sunday $MonthStart = 7; } $LastDay = date("d", mktime(0,0,0,$Month+1, 0, $Year)); $StartDate = -$MonthStart; for ($k=1;$k<=6;$k++){ //print six rows for six possible weeks echo"<tr>"; for ($j=1;$j<=7;$j++){ //seven columns per row $StartDate++; if($StartDate < $LastDay) { //blank calendar space if($StartDate > 0) { echo"<td>$StartDate</td> \n"; } else { echo"<td bgcolor=\"#eeeeee\"></td> \n"; } } elseif (($StartDate <=1) && ($StartDate >= $LastDay)) { //date goes here if($StartDate >= 0) { echo"<td>$StartDate</td> \n"; } } } echo"</tr>"; } //End Table Row echo "</table>"; ?> <hr width="200"> <form action="cal.php" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="GET" > <?php echo "<select name=\"Month\">"; for($m=1;$m<=12;$m++){ $selected = ""; $longDate = date("F", mktime(0,0,0,$m,1,$Year)); if ($Month==$m){ $selected = "selected "; } echo "<option value=\"$m\" $selected>$longDate</option> \n"; } echo "</select>"; echo "<select name=\"Year\">"; $yeartoday = date(Y); $yearplus1 = date(Y)+1; for($y=$yeartoday;$y<=$yearplus1;$y++){ $selected = ""; $longDate = date("Y", mktime(0,0,0,1,1,$y)); if ($Year==$y){ $selected = "selected \n"; } echo "<option value=\"$y\" $selected>$longDate</option> \n"; } echo "</select>"; ?> <input type="submit" value="go"> </form> </div> </body> </html> This works. In your above post you missed $ on for($y=yeartoday;$y<=$yearplus1;$y++){ ... yeartoday Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Author Share Posted March 19, 2009 Thanks Daney11. Case closed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.