JAVA、PHP、前端、APP、网站开发 - 开发技术学习

开发技术学习 » 编程开发 » PHP文章按日期(月日)SQL归档语句

PHP文章按日期(月日)SQL归档语句

此文被围观3668日期: 2014-04-25 分类 : 编程开发  标签:  ····

先看我的实际操作使用:

$article = M('Article');
        $data = $article->field("id,title,add_time")->where("status=1 and is_del=0")->order("id desc")->select();
        foreach ($data as $k=>$v){
            $y = date("Y", strtotime($v['add_time']));
            $m = date("m", strtotime($v['add_time']));
            $list[$y][$m][] = $v;
        }
        $this->list = $list;

感觉要比网上所说的简单多了。


以下为转载内容:


PHP文章按日期(月日)SQL归档PHP文章按日期(月)SQL归档实现语句,需要的朋友可以参考下

select FROM_UNIXTIME(pubtime, '%Y-%m') as pubtime, count(*) as cnt from articles group by FROM_UNIXTIME(pubtime, '%Y-%m')

PHP文章按日期(日)SQL归档 

select FROM_UNIXTIME(pubtime, '%Y-%m-%d') as pubtime, count(*) as cnt from articles group by FROM_UNIXTIME(pubtime, '%Y-%m-%d')

非时间戳日期格式归档(date_format格式化日期) 

select date_format(`post_date`,'%Y%m%d') as pubtime, count(*) as cnt from wp_posts where `post_status`='publish' group by date_format(`post_date`,'%Y%m%d') order by `ID` desc ;
select date_format(`post_date`,'%Y%m%d') as pubtime,date_format(`post_date`,'%m 月 %d 日') as shijian,count(*) as cnt from wp_posts where `post_status`='publish' group by date_format(`post_date`,'%Y%m%d') order by `ID` desc limit 0,7


站点声明:部分内容源自互联网,为传播信息之用,如有侵权,请联系我们删除。

© Copyright 2011-2024 www.kfju.com. All Rights Reserved.
超级字帖 版权所有。蜀ICP备12031064号