我的查詢不起作用。我正在使用codeigniter。我想根據日期範圍篩選獲取這些記錄的列表。如何獲取特定日期範圍內的記錄
這裏是我的控制器:
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的日期格式後
$ fromdt和$託德的樣子後ü將它們轉換爲Y-M-d? –
其2014-04-02 – rbstack
當沒有表12時,你寫了'table12.quote_id'。你也在做'AND table2.dairy_dt> ='$ from'AND table1.dairy_dt <='$ to''。這些應該來自同一個表 – Tom