Because, um, October plus three months is January, and 1 is less than 10.
Here's the code; formatted for readaibility and with a debugging message included.
<?php
$min = explode('-', date('Y-m-d'));
$max = explode('-', date('Y-m-d', mktime(0, 0, 0, ($min[1] + 3), $min[2], $min[0])));
$dtremove= explode('-', $datetoremove);
$year=$dtremove[0];
$month=$dtremove[1];
$day=$dtremove[2];
?>
<tr><td><b>Date to Remove </b><font size=small>Day/Month/Year</font><br></td>
<td>
<select name="day" id="day">
<?php
for($j = 1; $j <= 31; $j++)
{
if($j== $day){
?>
<option selected value="<?php echo $j; ?>"><?php echo $j; ?></option>
<?php
}else{
?>
<option value="<?php echo $j; ?>"><?php echo $j; ?></option>
<?php
}
}
?>
</select>
<?php
echo '$min[1] currently equals '.$min[1].' and $max[1] currently equals '.$max[1].'<br>';
?>
<select name="month" id="month">
<?php
for($i = $min[1]; $i <= $max[1]; $i++)
{
if($i== $month){
?>
<option selected value="<?php echo $i; ?>"><?php echo date('F', mktime(0, 0, 0, $i, 1, $min[0])); ?></option>
<?php
}else{
?>
<option value="<?php echo $i; ?>"><?php echo date('F', mktime(0, 0, 0, $i, 1, $min[0])); ?></option>
<?php
}
}
?>
</select>
<select name="year" id="year">
<option value="<?php echo $min[0]; ?>"><?php echo $min[0]; ?></option>
<?php if($max[0] != $min[0]){
?>
<option selected value="<?php echo $max[0]; ?>"><?php echo $max[0]; ?></option>
<?php
}
?>
</select>
Here's what's possibly the smallest possible change to make it work.
<select name="month" id="month">
<?php
for($i = $min[1]; $i <= $min[1]+3; $i++)
{
$m = ($i%12);
if($m==0) $m=12;
if($m==$month){
?>
<option selected value="<?php echo $i; ?>"><?php echo date('F', mktime(0, 0, 0, $m, 1, $min[0])); ?></option>
<?php
}else{
?>
<option value="<?php echo $i; ?>"><?php echo date('F', mktime(0, 0, 0, $m, 1, $min[0])); ?></option>
<?php
}
}
?>
</select>
Note: significantly better code could (and should) be written. E.g., initialise a $months array as
$months = array();
for($i=1; $i<=12; $i++)
{ $months[$i]=date('F',mktime(0,0,0,$i,1,2004));
}
$months = array_merge($months,$months); // Yes, duplicate.
$month = 5;
// Then four months starting from $month would be
for($i=$month-1; $i<=$month+2; $i++) // Our array counts January as month 0.
{ echo $months[$i].'<br>';
}