2016-11-21 52 views
0

我有這個代碼來過濾產品價格,但我仍然困惑於使用兩個變量爲SELECT WHERE...BETWEEN查詢。這是代碼:如何查詢SELECT WHERE ... BETWEEN兩個變量

$min=$this->input->post('minValue'); 
$max=$this->input->post('maxValue'); 
$this->db->select('*'); 
$this->db->from('msproduct'); 
$this->db->where('ProductPrize BETWEEN $min AND $max'); 
$query = $this->db->get(); 
data['product']=$query->result(); 
$this->load->view("user/product/product_filter",$data); 

而且我得到這個錯誤:

Unknown column '$min' in 'where clause'

+1

嘗試'$這個 - > DB->其中( 「ProductPrize介於$ min和$最大」);' –

回答

3

這也許是因爲$min$max變量沒有

$this->db->where('ProductPrize BETWEEN $min AND $max'); 

變化來評估,要

$this->db->where("ProductPrize BETWEEN $min AND $max"); 

注意報價。 '不計算PHP變量內,但"做評估他們

0

你可以試試這個:

$min=$this->input->post('minValue'); 
$max=$this->input->post('maxValue'); 
$this->db->select('*'); 
$this->db->from('msproduct'); 
$this->db->where('ProductPrize >=', $min); 
$this->db->where('ProductPrize <=', $max); 
$query = $this->db->get(); 
data['product']=$query->result(); 
$this->load->view("user/product/product_filter",$data);