[英]CakePHP: Random query with one result, exclude two values
我嘗試在隨機查詢中排除兩個值,但它被忽略了。 也許你們中的一位可以啟發我。 這是我的代碼:
$random = $this->Gerde
->find('all', [
'conditions' => [
'OR' => [
'NOT' => [
['employees' => 'BLUE'],
['employees' => 'RED']
]
]
]
])
->order('rand()')
->first();
我得到了我的單一隨機結果,但無論如何都會出現紅色和藍色員工。 我的邏輯很爛嗎? 提前致謝。
GregSchmidts 的回答是正確的。 我的代碼現在看起來像這樣,並且像魅力一樣工作:
$random = $this->Gerde->find('all', ['conditions' => ['employees NOT IN' => ['BLUE','RED'] ] ])
->order('rand()')
->first();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.