我怎样才能从mysql数据库codeigniter框架中获得每周发布

问题描述:

我怎样才能从codeigniter框架中的mysql数据库获得每周发布。我不明白如何做到这一点,逻辑是什么? 我的数据库表:我怎样才能从mysql数据库codeigniter框架中获得每周发布

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)

//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'是你的列名,确保这是您在数据库中输入记录时放置当前日期的列。