Hi all,
I am a bit of a newbie to PHP but trying never less. I am using the following code, which uses a for loop to get the latest month and then display 10 (just a random number) previous months below it inside a drop down list.
The problem I am having is that instead of displaying October 2007 --> December 2006 I want the drop down list to start from the current month (October 2007 - obviously) then below it have September 2007, which is when my data starts from. September 2007 will always be the starting month, so as time goes on, say in January 2008 I need my drop down list to display:
January 2008
December 2007
November 2007
October 2007
September 2007
Hope I explained this problem ok.
Here is my code:
echo 'Filter by month:';
echo '<select name="month">';
echo '<option value="?month=">All months</option>';
$beginning_month = 10;
for($x=0;$x<$beginning_month;$x++){
$time = strtotime("$x months ago");
$month = date("F Y",$time);
$link = strtolower(date("MY",$time));
if(isset($_GET['month']) && $link == $_GET['month']) {
echo '<option value="'.$link.'" selected="selected">'.$month.'</month>';
} else {
echo '<option value="'.$link.'">'.$month.'</month>';
}
}
echo '</select>';
echo '<input type="submit" value="Filter" />';
Can anyone please help?