Friday, 3 June 2016

PHP Display next 10 months and past 10 months including this month with year

<?php
for ($i=0; $i<10; $i++)
{
    $timestamp = mktime(0,0,1,date("m")+$i,date("d"),date("Y"));
    $month = date("F Y", $timestamp);
    echo "{$month}<br />\n";

?>

For Past 10 months including this month
Filter by month:<select name="month">
<option value="?month=">All months</option>
<?php
$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" />'; 
?>


0 comments:

Post a Comment