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