[英]using array in WHERE IN in CakePHP
我正在开发CakePHP 3.2
我想在查询WHERE IN ()
使用数组
代码是
$filter_p_t = $this->request->query('p_t');
$pros10 = $this->Products->find()
->where([
'SellerProducts.stock >' => 0,
'SellerProducts.status' => 1,
'Products.p_status' => 1,
])
->contain([
'SellerProducts',
'ProductTypes.Subcategories.Categories',
]);
这里$filter_p_t
是来自带参数的url的数组
/products/display/1?p_t[]=1&p_t[]=86
我想将$filter_p_t
包含在where
条件中以查找所有IN(1,86)
如何在CakePHP 3中使用php数组到WHERE IN条件?
您可以在列之后直接使用IN
关键字。 这假设$filter_p_t
是一个类似array(1, 86)
$filter_p_t
array(1, 86)
。
->where(['id IN' => $filter_p_t]);
http://book.cakephp.org/3.0/en/orm/query-builder.html#automatically-creating-in-clauses
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.