首先你需要得到下周一的日期
$next_monday = new DateTime('next monday');
然后获得周末(如果需要):
$date = $next_monday->format('Y-m-d').' 23:59:59'; //Get monday at 23:59
$end_week = strtotime("+7 day", $date); //Get sunday at 23:59
然后在您的 Codeigniter 模型中,使用 Active Records:
public function nextWeekData($monday, $sunday){
$this->db->where("your_date_field >= '". $monday->format('Y-m-d H:i:s')."' AND your_date_field <= '". $sunday->format('Y-m-d H:i:s')."'");
$this->db->get('your_table');
return $this->db->result_array(); // If you want an array
// return $this->db->result(); // If you want StdClass
}
所以来自你的控制器的调用应该是:
$this->my_model->nextWeekData($next_monday, $end_week);
如果不需要上限,只需删除模型中 WHERE 语句中的 $end_week 和第二个子句即可。
我认为应该这样做。代码未测试。 重要提示:注意where中的引号。