[英]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.