【问题标题】:Fill dropdown list with month and year using php使用php用月份和年份填写下拉列表
【发布时间】:2014-04-09 19:17:56
【问题描述】:

好吧,我无话可问!抱歉,如果我未能解决我的问题。

好吧,我的数据库中有一条员工记录,他于 2012 年 3 月加入公司,现在是 2014 年 4 月。我只需要使用从当前月份、年份到加入的月份和年份填充下拉组合框php。最后下拉列表看起来像

2014 年 4 月

2014 年 3 月

2014 年 2 月

2013 年 2 月

【问题讨论】:

    标签: php mysql


    【解决方案1】:
    $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>';
    

    【讨论】:

      猜你喜欢
      • 2015-01-14
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      相关资源
      最近更新 更多