2017-04-11 75 views
0

在这里,我想根据我想举,但返回回到整个结果的日期得到的结果 的DATABSE看起来像这样让所有值,而不是获得搜索结果

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-201703-01-2017之间的日期,那么也会显示整个结果。问题只是前两个值从日期考虑,例如,如果我考虑01-01-2017这里只有01正在考虑并保留not.please帮我解决这个问题

+0

尝试使用打印查询'$这个 - > DB-> last_query()' –

+0

整个结果取 –

+0

你打印查询?执行你的mysql控制台上的打印查询 –

回答

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); 
+0

没有什么显示,而使用此 –

+0

如果你正在得到结果,所以它应该打印正在执行的查询 –

+0

SELECT * FROM'customer' WHERE'category_id' = 2越来越喜欢这个 –

0

试试这个先生

$this->db->order_by('customer_account_id DESC'); 
    $this->db->limit('1'); 
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  
} 
+0

知道是什么结果? –

+0

现在没有任何显示 –