这里我希望根据我想提供的日期得到结果,但返回整个结果 数据库看起来像这样
customer_account_id customer_id date code
11 55 01-01-2017 ALI HAJI
12 55 02-01-2017 ALI HAJI
13 55 03-01-2017 ALI HAJI
125 65 01-02-2017 SHARFU
126 55 02-02-2017 ALI HAJI
127 55 03-02-2017 ALI HAJI
128 55 31-01-2017 ALI HAJI
控制器看起来像这样
public function report()
{
$from=$this->input->post('from_date');
$to = $this->input->post('to_date');
$from1= date('d-m-Y', strtotime($from));
$to1= date('d-m-Y', strtotime($to));
$data['result']= $this->Account_model->get_report($from1,$to1)->result();
$this->load->view('report_payment_details',$data);
}
我的模型看起来像这样
public function get_report($from1,$to1)
{
$this->db->order_by('customer_account_id','desc');
$this->db->where('date >=', $from1);
$this->db->where('date <=', $to1);
return $this->db->get('customer_accounts');
}
如果我选择01-01-2017
和03-01-2017
之间的日期,那么也会显示整个结果。问题是从日期开始考虑的前两个值,例如我是否考虑01- 01-2017这里只有01正在考虑并且仍然没有。请帮助我解决这个问题
答案 0 :(得分:0)
首先,列的datatype
应为date
。请尝试以下代码。
$this->db->order_by('customer_account_id','desc');
$this->db->where('date >=', $from1);
$this->db->where('date <=', $to1);
$result = $this->db->get('customer_accounts');
echo $this->db->last_query();
print_r($result);
答案 1 :(得分:0)
试试这个先生
$this->db->order_by('customer_account_id DESC');
$this->db->limit('1');
答案 2 :(得分:0)
public function get_report($from1,$to1)
{
$this->db->order_by('customer_account_id','desc');
$this->db->where('date >=', $from1);
$this->db->where('date <=', $to1);
$this->db->get('customer_accounts');
echo $this->db->last_query(); // dont return it now just check
}