Can anyone sport the deliberate mistake in this code.
It worked fine until we moved into November, now it just hits an infinite loop 🙁
The basic idea is to create drop-down boxes for a report generator.
The dates should start at April 2002 and go until the current month.
TIA
Jamie
//create the from and to dates drop down boxes.
$year=2002;
$month=4;
$now = getdate(mktime());
$this_month=$now[mon]+1;
$this_year = $now[year];
$start_date_select = "<select name=\"start_date\">\n";
$end_date_select ="<select name=\"end_date\">\n";
if (isset($start_date))
{
//start_date given, is there an end date?
if (isset($end_date))
{
//end date given, good.
}
else
{
//make end date today
$end_date = mktime(0,0,0,$this_month,0,$this_year);
}
}
else
{
//no start date given is there an end date ??
if (isset($end_date))
{
//end date given, good.
}
else
{
//no end date, make that today.
$end_date = mktime(0,0,0,$this_month,0,$this_year);
}
//make start date 1st April 2002 as this is the start date of the database
$start_date = mktime(0,0,0,4,1,2002);
}
//set the texts for the page title
$start_date_text = date ("d/m/Y", $start_date);
$end_date_text = date("d/m/Y", $end_date);
while($year<$this_year || $month<=$this_month)
{
$start_select_date = mktime(0,0,0,$month,1,$year);
$end_select_date = mktime(0,0,0,$month,0,$year);
$last_day_of_month = date("j", $end_select_date);
$start_select_value = date("d M, Y", $start_select_date);
$end_select_value = date("d M, Y", $end_select_date);
if ($month == 4)
{
//only do the start select's option
if ($start_date == $start_select_date)
{
$start_date_select .= "\n\t<option value=\"$start_select_date\" selected>$start_select_value</option>";
}
else
{
$start_date_select .= "\n\t<option value=\"$start_select_date\">$start_select_value</option>";
}
}
elseif ($month == $this_month)
{
//only do the end select's option
if ($end_date == $end_select_date)
{
$end_date_select .= "\n\t<option value=\"$end_select_date\" selected>$end_select_value</option>";
}
else
{
$end_date_select .= "\n\t<option value=\"$end_select_date\">$end_select_value</option>";
}
}
else
{
//do both selects
if ($start_date == $start_select_date)
{
$start_date_select .= "\n\t<option value=\"$start_select_date\" selected>$start_select_value</option>";
}
else
{
$start_date_select .= "\n\t<option value=\"$start_select_date\">$start_select_value</option>";
}
if ($end_date == $end_select_date)
{
$end_date_select .= "\n\t<option value=\"$end_select_date\" selected>$end_select_value</option>";
}
else
{
$end_date_select .= "\n\t<option value=\"$end_select_date\">$end_select_value</option>";
}
}
if(++$month==13)
{
$month=1;
$year++;
}
}