Jump to content

Need help with a for loop


rcorlew

Recommended Posts

I have a loop that I am trying to run through 12 times. It starts off just fine except that it runs through the loop for 1969 times.

 

I have no idea what I am doing wrong as this very code works elsewhere but not for this.

 

<?php

$year  = isset($_GET['year']) ? $_GET['year'] : date('Y'); 
$month = isset($_GET['month']) ? $_GET['month'] : date('m');

  $first       = mktime(0,0,0,$month,1,$year); // timestamp for first of the month 
  $offset      = date('w', $first); // what day of the week we start counting on 
  $daysInMonth = date('t', $first); 
  $monthName   = date('F', $first); 
   echo
   "<select name=\"month\" onChange=\"document.location.href=this.value\" class=\"topNavSelect\">
  	<option>$monthName</option>";
   
   $x = 1;
   $y = 12;
   			for( $i = $x; $i <= $y; $i++ ) {
   				
			$thisMonth = strtotime("$year-$month-01 $i month");
			$nMax = date('t', $thisMonth);
			$nDay = ($day > $nMax) ? $nMax : $day;

		list($y, $m) = explode('-', date('Y-m', $thisMonth));

				$thisMonth =  date('F', $thisMonth);
				$showMonth = "?year=$y&month=$m&day=";
				$myMonth = $thisMonth;

				echo "<option value=\"$showMonth\">$myMonth $i $y</option>";

			}

echo "</select>";
?>

 

I am sure that it is something simple that I have overlooked.

Link to comment
https://forums.phpfreaks.com/topic/96348-need-help-with-a-for-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.