我想从表中获取以a,b或c开头但在cakephp 3.0中状态= pending的名称的记录。我正在尝试以下查询。请检查它有什么问题,因为它还从名称开始提取结果':
$this->loadModel('DbArtists');
/*** fetching records alphabetically ***/
$artists_q = $this->DbArtists->find()->where(['album_status' => 'pending'])->orWhere(['name ' => 'A%', 'name ' => 'B%', 'name' => 'C%']);
$artist = $artists_q->all();
echo "<pre>";print_r($artist);die;
答案 0 :(得分:3)
如下所示: -
$artists_q = $this->DbArtists->find()->where([
'album_status' => 'pending',
'OR' => [['name LIKE' => 'A%'],['name LIKE' => 'B%'],['name LIKE' => 'C%']],
]);
或者你也可以这一次: -
$query = $articles->find()->where(['album_status' => 'pending'])
->orWhere(['name LIKE' => 'A%'])
->orWhere(['name LIKE' => 'B%'])
->orWhere(['name LIKE' => 'C%']);
参考: - https://book.cakephp.org/3.0/en/orm/query-builder.html