【发布时间】:2016-01-13 04:21:50
【问题描述】:
这里有点难以解释,但我会尽力包含所有相关信息。不明白的可以问我。
上面是我得到的数据,我希望将相同的数字(例如 2016)组合起来,如下所示。
这是我的代码。
<?php
$years = mysql_query("SELECT DISTINCT YEAR(event_date) as years, DATE_FORMAT(event_date,'%b') as months from news WHERE status<>'deleted' and status<>'draft' ORDER BY years DESC");
while($page=mysql_fetch_array($years))
{ ?>
<div class="date">
<div class="year"><a href="<?php echo $sys_domain; ?>/news/index.php?year=<?php echo $page['years'] ?>&month=<?php echo $page['months'] ?>"><?php echo $page['years']; ?></a></div>
<div class="month"><a href="<?php echo $sys_domain; ?>/news/index.php?year=<?php echo $page['years'] ?>&month=<?php echo $page['months'] ?>"><?php echo $page['months']; ?></a></div>
</div>
<?php } ?>
我可以知道如何合并年份吗?我使用“GROUP BY”但不能,它隐藏了第二行数据。或者我应该比较价值并结合它?但我不知道该怎么做。请帮忙,谢谢。
【问题讨论】:
标签: php mysql database row concatenation