2016-05-03 82 views
0

我的模型。如何獲得最後30天的codeigniter記錄

public function get_data() { 
    $this->db->select('*'); 
    $this->db->from('one_month_report'); 
      $this->db->where('store_date BETWEEN NOW() - INTERVAL 30 DAY AND NOW()'); 
    $query = $this->db->get(); 
    if ($query->num_rows() > 0) { 
     return $query->result(); 
    } else { 
     return FALSE; 
    } 
} 
+0

DB->選擇( '*'); $ this-> db-> where('date between DATE_SUB(NOW(),INTERVAL 30 DAY)and NOW()'); $ this-> db-> where($ conditions); $ result = $ this-> db-> get($ table); ?>是的,這是重複的問題。 – Mohini

回答

1

試試這個:

public function get_data() 
{ 
    $this->db->select('*'); 
    $this->db->from('one_month_report'); 
    $this->db->where('store_date BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE()'); 
    $query = $this->db->get(); 
    if ($query->num_rows() > 0) { 
     return $query->result(); 
    } else { 
      return array(); 
    } 
} 
+0

錯誤爲foreach()提供的參數無效 – Som

相關問題