Php 如何查询选择两个变量之间的位置
我有这段代码来过滤产品价格,但我仍然对使用两个变量进行Php 如何查询选择两个变量之间的位置,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有这段代码来过滤产品价格,但我仍然对使用两个变量进行选择WHERE…BETWEEN查询感到困惑。这是代码: $min=$this->input->post('minValue'); $max=$this->input->post('maxValue'); $this->db->select('*'); $this->db->from('msproduct'); $this->db->where('ProductPrize BETWEE
选择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);
我得到了这个错误:
“where子句”中的未知列“$min”
这可能是因为中未计算
$min
和$max
变量
$this->db->where('ProductPrize BETWEEN $min AND $max');
换成
$this->db->where("ProductPrize BETWEEN $min AND $max");
请注意引用
“
不会在内部计算php变量,但”
会对其进行计算这可能是因为$min
和$max
变量未在内部计算
$this->db->where('ProductPrize BETWEEN $min AND $max');
换成
$this->db->where("ProductPrize BETWEEN $min AND $max");
请注意引号。“
不会计算内部的php变量,但”
会计算它们的值。您可以尝试以下方法:
$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);
$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您可以尝试以下方法:
$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);
$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 try$this->db->where(“ProductPrize介于$min和$max之间”);
try$this->db->where(“ProductPrize介于$min和$max之间”);