【问题标题】:How can I get weekly post from mysql database in codeigniter framework如何在 codeigniter 框架中从 mysql 数据库中获取每周帖子
【发布时间】:2014-07-06 04:29:21
【问题描述】:

如何在 codeigniter 框架中从 mysql 数据库中获取每周帖子。我不明白该怎么做,逻辑是什么? 我的数据库表是:

id  | post_schedule_date  | post_name   |  post_description
-----------------------------------------------------------
1   | 29-06-2014          | Test title  |  Test description
-----------------------------------------------------------
2   | 30-06-2014          | Test title  |  Test description
-----------------------------------------------------------
3   | 01-07-2014          | Test title  |  Test description
-----------------------------------------------------------
4   | 02-07-2014          | Test title  |  Test description
-----------------------------------------------------------
5   | 02-07-2014          | Test title  |  Test description
-----------------------------------------------------------
6   | 03-07-2014          | Test title  |  Test description
-----------------------------------------------------------

我想要这样的输出:

本周 (5) 前一周(2)

【问题讨论】:

    标签: php mysql database codeigniter


    【解决方案1】:
    //Selects Current Week records 
    SELECT * FROM table_name WHERE post_schedule_date > DATE_SUB(NOW(), INTERVAL 7 DAY ) 
    AND created_at < curdate() + 1  ;
    
    //Selects Previous week
    SELECT * FROM table_name WHERE post_schedule_date > DATE_SUB(NOW(), INTERVAL 14 DAY ) 
    AND created_at < DATE_SUB(NOW(), INTERVAL 7 DAY ) ;
    

    这里 'post_schedule_date' 是您的列名,请确保这是您在数据库中输入记录时放置当前日期的列。

    【讨论】:

      猜你喜欢
      • 2018-07-26
      • 2011-08-03
      • 2018-01-27
      • 2011-04-08
      • 2022-12-09
      • 2021-11-08
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多