我有很多存储在数据库中,像这样的日期:提取月份和年份从MySQL日期格式
2017年6月1日
而且还有值得数据库中的数据的不同个月。我想在一个下拉菜单来显示这一点,以便用户将看到:
2017年4月 2017年5月2017年
我想这在while循环的开始独自尝试获得每月 六月:
$month = date('F', strtotime($row['b_date']));
但它只是显示1月7日。
$stmt = $link->prepare("SELECT 'b_date' FROM `summary`");
$stmt->execute();
$result = $stmt->get_result();
$numRows = $result->num_rows;
if($numRows > 0) {
while($row = $result->fetch_assoc()) {
$month = date('F', strtotime($row['b_date']));
echo "<option value=''>{$month}</option>";
}
}
很难说,没有看到这个和架构的代码。充其量,DISTINCT/GROUP BY? –
@ Fred-ii-刚刚编辑了问题以显示sql – Jonathan
请勿使用引号“'b_date'' – AbraCadaver