簡體   English   中英

在CakePHP中的WHERE IN中使用數組

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM