如何在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)
答案 0 :(得分:0)
//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'是您的列名,请确保这是您在数据库中输入记录时放置当前日期的col。