Php 如何将同一个月的日期显示为单个链接?

Php 如何将同一个月的日期显示为单个链接?,php,mysql,Php,Mysql,我的博客有一个档案区。每次有帖子时,我都希望它能自动将月份名称和年份显示为列表,以便以后我可以单击查看该月份和年份的帖子 我只知道如何使用mysql\u fetch\u assoc显示,但这会不断重复每一行,所以我尝试了分组方式,但也没有任何帮助 <div class="sidebox widget"> <h4>Por Datas</h4> <?php $query = "SELECT * FROM posts GROUP BY post_

我的博客有一个档案区。每次有帖子时,我都希望它能自动将月份名称和年份显示为列表,以便以后我可以单击查看该月份和年份的帖子

我只知道如何使用mysql\u fetch\u assoc显示,但这会不断重复每一行,所以我尝试了分组方式,但也没有任何帮助

<div class="sidebox widget">
    <h4>Por Datas</h4>

<?php 

$query = "SELECT * FROM posts GROUP BY post_date";
$select_all_post_by_dates = mysqli_query($connection, $query);

while($row = mysqli_fetch_assoc($select_all_post_by_dates)) {

$post_id = $row['post_id'];
$post_date = $row['post_date'];
$post_date_month_year = date_create($post_date)
?>

<ul class="circled">
<li>
<a href="#"><?php echo date_format($post_date_month_year, "F Y")  ?>
</a>
</li>
</ul><!-- /.circled -->

<?php } ?>
<a href="#" class="txt-btn">All archives</a>
</div><!-- /.widget -->

Por数据
结果是一个月比另一个月重复,例如:

2019年4月 2019年4月 2019年4月

万一我五月份还有一个职位

2019年4月 2019年4月 2019年4月 2019年5月

我需要:

2019年4月
2019年5月

按年度和月份分组

SELECT
  Year(`post_date`),
  Month(`post_date`),
  Day(`post_date`),
  Count(*) As Total_Rows
FROM posts 
GROUP BY Year(`post_date`), Month(`post_date`), DAY(`post_date`)

使用SELECT distinct post_date FROM POSTSM我的主要问题是使用php显示,用php部分补充会有很多问题吗?