2014-07-06 28 views
-1

我怎樣才能從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)

回答

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'是你的列名,確保這是您在數據庫中輸入記錄時放置當前日期的列。