简体   繁体   中英

Fill dropdown list with month and year using php

Ok, i don't have words to ask my question proprely! Sorry if i failed to dilever my question.

Well I have an employee record in my database who join the company in March, 2012 and now it is April, 2014. All i need to populate dropdown combo box with from current month, year down to month and year of joining using php. In last the dropdown looks like

Apr, 2014

Mar, 2014

Feb, 2014

to

Feb, 2013

$current = new DateTime();
$end = new DateTime('2012-04-11');

echo '<select>';
while ($current > $end) {
  echo '<option>' . $current->format('M, Y') . '</option>';
  $current->modify('-1 month');
}
echo '</select>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM