如何获取特定日期范围内的记录


How to get Records in Specific date range

我的查询不起作用。我正在使用代码点火器。我想根据日期范围过滤获取这些记录的列表。

这是我的控制器:

public function filter($type){
  $fromdt = date("Y-d-m",strtotime($this->input->post("from")));
  $todt = date("Y-d-m",strtotime($this->input->post("to")));
  $session_data = $this->session->userdata('logged_in');
  $this->load->model("mymodel");    
  print_r($this->mymodel->filterdata($fromdt,$todt,$session_data['id'])); 
}

这是我的模型:

public function filterdata($from,$to,$userid){
  $query = $this->db->query("SELECT table1.id,table1.quest,table1.post_id,table1.quote_id,table2.in_dairy FROM table1,table2 
  WHERE table2.quote_id = table1.id AND table2.reader_id='$userid' 
  AND table1.in_dairy='yes' AND table2.dairy_dt>='$from' AND 
  table2.dairy_dt<='$to'");
  return $query->result();
}

注意:我的dairy_dt字段是Mysql中的日期类型。我不知道为什么它显示一个空的结果..

更新函数后尝试

public function filter($type){
   $fromdt = date("Y-m-d",strtotime($this->input->post("from")));
   $todt = date("Y-m-d",strtotime($this->input->post("to")));
   $session_data = $this->session->userdata('logged_in');
   $this->load->model("mymodel");    
   print_r($this->mymodel->filterdata($fromdt,$todt,$session_data['id'])); 
}

MySql 日期格式如下:Y-m-d

如果不分配所做的查询,为什么要返回 $query->result()?我的意思是

$this->db->query("SELECT table1.....
return $query->result();

$query值在哪里?,你应该做

$query = $this->db->query("SELECT table1.....
return $query->result();