faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 15 people (80%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I create a dropdown for date field showing past 3 months, present month and the 12 months in the future?

Nov 27th, 2008 02:47
healthy man, dman, Onno Benschop, Niketan Pandit, http://www.ttnr.org


<?
function monthDropDown($today = 'today', $start = -3, $end = 12) {
  /*
    Author: Onno Benschop
    Date:   Monday, 23 April 2001
    Usage:  Returns a popup list using today's date as the default.
            Specify start as a negative number.
            Specify end as a positive number
  */
  if ($today=='today') {
    $today = date('n') ;
      // month as a number without leading 0
  }
  $theResult = '<select name=month>' ;
  for ($month = $today + $start ; $month < $today + $end ; $month++) {
    $theResult .= '<option '.
      ($month==$today?'selected ':'').
        // this is the default option
      'value='.
      $month.
      '>'.
      date ('F', mktime (0,0,0,$month,1,2001)).
        // extract the name of the month
      '</option>' ;
  }
  $theResult .= '</select>' ;
  return $theResult ;
}
echo '<form>default, 3 months before today, 12 months after' ;
echo monthDropDown() ;
// default, 3 months before today, 12 months after
echo '</form>' ;
echo '<form>3 months before june, 12 months after' ;
echo monthDropDown(6) ;
// 3 months before june, 12 months after
echo '</form>' ;
echo '<form>12 months before june, 2 months after' ;
echo monthDropDown(6,-12,2) ;
// 12 months before june, 2 months after
echo '</form>' ;
?>
http://www.healthdothealth.com
http://www.healthxhealth.com
http://www.mesotheliomainmesothelioma.com
http://www.healthfirewall.com
http://www.flathealth.com
http://www.healthbodyguard.com