它没有返回标题.
那么我可以在查询中更改什么?
那么我可以在查询中更改什么?
$query = (new Query())->select('title')->from('topics')->where(['id' => [1,2,3]]); return $query->title;
解决方法
您的查询形成如下 –
SELECT title FROM topics WHERE id IN (1,3);
所以你将获得数组的数组.您还需要执行查询.
试试 –
$query = (new \yii\db\Query())->select(['title'])->from('topics')->where(['id' => [1,3]]); $command = $query->createCommand(); $data = $command->queryAll(); $titles = ''; foreach($data as $row) { $titles .= $row['title'] . ','; } return rtrim($titles,',');
您将获得每条记录的标题,逗号分隔.