Php:档案系统像博客 [英] Php: Archives system like blog

查看:161
本文介绍了Php:档案系统像博客的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,我有一个新闻页面,客户可以添加无限数量的新闻(日期存储在数据库中(CURRENT_TIMESTAMP))。

On my website, I have a "news" page where the customer can add an unlimited number of news (dates are stored in the DB ( with CURRENT_TIMESTAMP )).

例如,当用户在7月份点击时,只有7月份的消息才会出现在页面上。

For example when the user clicks on July, only news of July will be appear on the page.

现在,我只有这样:

<?php
    $q = $db->query("SELECT dateNews FROM news GROUP BY dateNews");

    while($data = $q->fetch()){
        $dateMonth= $data['dateNews'];
        echo "<a href='#''><p>".strftime('%B %Y', strtotime($dateMonth))."</span></p></a>";
    }                   
?>

但是我想要这样:

我的日期正确列出,但我真的不知道如何解决问题。

My dates are listed correctly, but I do not really know how to solve the problem.

有人可以帮我吗?

编辑:

经过多次研究,我找到了一个合并该月的解决方案:

After much research, I found a solution for merge the same months :

<?php                   
    $q = $db->query("SELECT YEAR(dateNews) AS YEAR, MONTH(dateNews) AS MONTH, COUNT(*) AS newsCount FROM news GROUP BY YEAR, MONTH");

    while($data = $q->fetch()){
        $dateMonth = $data['MONTH'];
        echo "<a href='#''><p>".utf8_encode(strftime('%B %Y', strtotime($dateMonth)))." (" . $data['newsCount'] . ")</span></p></a>";
    }
?>

月份正确合并,但现在我有另一个问题,我无法解决:

Months are correctly merged, but now I have another problem that I can't resolve :

我真的不知道该怎么做或怎么做。有人知道吗?

I really don't know what to do or how to do. Somebody knows something ?

推荐答案

假设 dateNews 是月它似乎是),那么你几乎得到了。您只需要选择每个分组的计数,然后显示它。

Assuming that dateNews is the month (which it appears to be), then you've almost got it. You just need to also select the count of each grouping and then display it.

<?php
    $q = $db->query("SELECT dateNews, COUNT(*) AS newsCount FROM news GROUP BY dateNews");

    while($data = $q->fetch()){
        $dateMonth= $data['dateNews'];
        echo "<a href='#''><p>".strftime('%B %Y', strtotime($dateMonth))." (" . $data['newsCount'] . ")</span></p></a>";
    }                   
?>

这篇关于Php:档案系统像博客的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆