It returns no title. So what can I change in the query?
$query = (new Query())->select('title')->from('topics')->where(['id' => [1, 2, 3]]);
return $query->title;
Your query is formed something like -
SELECT title FROM topics WHERE id IN (1,2,3);
So you will get array of array. Also you need to execute the query.
Try -
$query = (new \yii\db\Query())->select(['title'])->from('topics')->where(['id' => [1, 2, 3]]);
$command = $query->createCommand();
$data = $command->queryAll();
$titles = '';
foreach($data as $row) {
$titles .= $row['title'] . ', ';
}
return rtrim($titles, ', ');
You will get the title
for each record, comma separated.
Try this code:
$users=[1,2,3];
User::find()->where('id IN('.$users.')');
[
'attribute' => 'topic_id',
'format' => 'raw',
'value' => function($data){
$query = (new Query())->select(['title'])->from('topics')->where(['id' => [1, 2, 3]]);
$command = $query->createCommand();
$data= $command->queryAll();
foreach($data as $row)
return $data['title'];
}
],
m put this code but here error generate this.
Undefined index: title
title is available for topics table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With