E
E
EvgMul2015-10-26 14:58:18
Yii
EvgMul, 2015-10-26 14:58:18

Yii2 how to correctly fetch data from the database and display it?

Hello, I've run into this problem.
I write the following code:

$answers = Answers::findOne(['ticket_id' => '47']);
        echo $answers->title;

Everything perfectly displays one record. As it should.
But if I write this code:
$answers = Answers::find()->where(['ticket_id'=> '47']);
foreach ($answers as $answer) {
            echo $answer->title." ";
        }

That as a result I do not receive anything. Please tell me where I missed and how to fix the problem. Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Bojczuk, 2015-10-26
@EvgMul

all/one after where forgot:

$answers = Answers::find()->where(['ticket_id'=> '47'])->one();

H
holfza, 2015-10-26
@holfza

You can also do this: c2n.me/3pofkD3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question