Jump to content

[SOLVED] HOW CAN I SET THE SELECT OPTION SO IT AUTOMATICALLY UPDATES?


matt.sisto

Recommended Posts

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. 8)

Link to comment
Share on other sites

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 ????

Link to comment
Share on other sites


<!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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.