S
S
Space2015-06-01 13:13:17
Yii
Space, 2015-06-01 13:13:17

How to make a selection correctly in yii2?

I want to select records from a DB in a column where only integer values ​​are stored.
But I need to select only unique records i.e. if the number is encountered repeatedly, then we do not pull out the data.
I know how to implement it, but I do several cycles. Too crooked I'm afraid. How can this be done?

//$array массив данных колонки с int значениями.
//$stop пустой массив.

if($stop===null){
    echo $array['myint];
    $stop[] = $array['myint];
}else{
    for($i=0;$i<count($stop);$i++){
        if($stop[i]!=$array['myint]){
            echo $array['myint];
            $stop[] = $array['myint];
        }
    }
}

//Плюс оборачиваю в еще один цикл, чтобы прогнать через все записи.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-06-01
@ruslite

SELECT DISTINCT or in yii2 you can Model::find()->select('myint')->distinct();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question