S
S
Sergey Beloventsev2017-01-21 17:32:21
Yii
Sergey Beloventsev, 2017-01-21 17:32:21

How to get the last value of a field from a model?

there is a model, a table (as you like), here is the name of the fields -
'id','name','id_operation'
idautoincrement
id_operation- can be the same for several records.
I need to get the last value id_operation, given that the numbering is ascending from zero.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-01-23
@Sergalas

I need to get the last value of id_operation, given that the numbering is ascending from zero.

then your last value will be the maximum. If you need to get only the field value, use
if you need to get all the model data - use the option suggested by Maxim Timofeev

M
Maxim Timofeev, 2017-01-21
@webinar

$model = Model::find()->orderBy('id_operation DESC')->one();
echo $model->id_operation;

Or did I misunderstand?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question