如何在 Cakephp 3 中获取两个给定值之间的值
How to get values between two given values in Cakephp 3
我想使用以下查询获取具有指定价格范围的产品,但出现以下错误:
Cannot convert value to string InvalidArgumentException
$product_List=$this->Products->find('all',array('conditions' => array('product_price BETWEEN ? and ?' => array($min, $max))));
这里product_price是varchar(100)类型。请帮助解决我的问题。
我觉得对你有帮助
$product_List = $this->Products->find('all')
->where(function ($exp) use($min,$max) {
return $exp->between('product_price', $min, $max); //Consider $min=100 ; $max =1000; product_price BETWEEN 100 AND 1000;
});
另一种方式。
$product_List = $this->Products->find('all')
->where(['product_price <=' => $max, 'product_price >=' => $min]);
我想使用以下查询获取具有指定价格范围的产品,但出现以下错误:
Cannot convert value to string InvalidArgumentException
$product_List=$this->Products->find('all',array('conditions' => array('product_price BETWEEN ? and ?' => array($min, $max))));
这里product_price是varchar(100)类型。请帮助解决我的问题。
我觉得对你有帮助
$product_List = $this->Products->find('all')
->where(function ($exp) use($min,$max) {
return $exp->between('product_price', $min, $max); //Consider $min=100 ; $max =1000; product_price BETWEEN 100 AND 1000;
});
另一种方式。
$product_List = $this->Products->find('all')
->where(['product_price <=' => $max, 'product_price >=' => $min]);