我试图从数据库中获取日期,只将其中的月份和年份存储到var中,用结果填充下拉淹没列表,但删除任何重复的月份和年度。
例如,我的下拉列表显示:
- 2014年6月
- 2014年6月
- 7月14日
- 8月14日
- 8月14日
- 8月14日
- 9月14日
- 1月15日
- 2月15日
- 6月15日
- 6月15日
我只想让它显示每个选项一个月(带年份)。
这是我的代码:
<select name="month">
<?php
$sSDate = "SELECT DISTINCT eventStartDate FROM te_events GROUP BY eventStartDate ORDER BY eventStartDate ASC";
$qrSDate = mysql_query($sSDate) or die (mysql_error());
while($rowSDate = mysql_fetch_assoc($qrSDate))
{
$s_event_start_date = $rowSDate ['eventStartDate'];
$sGetStartDate = strtotime($s_event_start_date);
$sFormattedStartDate = date('M y', $s_event_start_date );
echo '
<option value="'.$sFormattedStartDate.'">
'.$sFormattedStartDate.'
</option>
';
}
?>
</select>
使用sql:从中选择不同的年份(eventStartDate)、月份(eventStartDate)。。。