-4

I currently found this date function a while back that works fine ( can't remember where i found it) but it displays all days, months and years from 2013. The problem is now I need people to be able to select 2014 from the drop down as well. Not really sure what I should edit to add this.

Thanks for any help... the code:

function date_dropdown($year_limit = 0){

   $daynow = date("d");
   $monthnowtxt = date('F');
   $monthnow = date('m');
   $yearnow = date("20y");

   $html_output = '<div id="date_select" >'."\n";
   $html_output .= '<label for="date_day">Date of Longplay</label>'."\n";

    /*days*/
   $html_output .= '<select name="date_day" id="day_select"><option  ="selected" value="' . $daynow . '">' . $daynow . '</option>'."\n";
   for ($day = 1; $day <= 31; $day++) {
       $html_output .= '<option>' . $day . '</option>'."\n";
   }
  $html_output .= '</select>'."\n";

    /*months*/
  $html_output .= '<select name="date_month" id="month_select" ><option selected="selected" value="' . $monthnow . '">' . $monthnowtxt . '</option>'."\n";
  $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  for ($month = 1; $month <= 12; $month++) {
      $html_output .= '               <option value="' . $month . '">' . $months[$month] . '</option>'."\n";
   } 
   $html_output .= '</select>'."\n";

   /*years*/
   $html_output .= '<select name="date_year" id="year_select"><option ="selected" value="' . $yearnow . '">' . $yearnow . '</option>'."\n";
   for ($year = 1900; $year <= (date("Y") - $year_limit); $year++) {
           $html_output .= '               <option>' . $year . '</option>'."\n";
   }
   $html_output .= '</select>'."\n";

   $html_output .= '</div>'."\n";
   return $html_output;
  }
4

4 回答 4

3

this method call gives you 2014:

date_dropdown(-1);
于 2013-10-03T09:51:59.940 回答
1

This is the bit you need to change

for ($year = 1900; $year <= (date("Y") - $year_limit); $year++)

date('Y') will return 2013

date('Y')+1 will return 2014

for ($year = 1900; $year <= ((date("Y")+1) - $year_limit); $year++)

I have to say I don't like the function you included and there are probably cleaner more flexible ways to do what it does.

于 2013-10-03T09:49:51.110 回答
1

change this

for ($year = 1900; $year <= (date("Y") - $year_limit); $year++)

to this

for ($year = 1900; $year <= ((date("Y")+1) - $year_limit); $year++)
于 2013-10-03T09:53:59.077 回答
1

Change your for loop

for ($year = 1900; $year <= (date("Y") - $year_limit); $year++)

to

for ($year = 1900; $year <= $year_limit); $year++)

and pass an argument something greater than 2014...

于 2013-10-03T09:54:17.597 回答