0

I am trying to build the query for search, here it is

        $searchResult = Candidate::find()
        ->select('HRMS_candidateID, HRMS_candidateFirstName','HRMS_candidateMiddleName')
        ->where(['LIKE', 'HRMS_candidatePrimarySkills', $keywordsArrayTrimed[$i]])

        ->all();

As I have $keywordsArrayTrimed[$i] which contains keywords, the number count of keywords is different on each request how to achieve this.

I have tried using for loop, it throes an error Unexpected for loop.

I tired using filter Like this

 $searchResult->andFilterWhere([
            'or',
            ['like', 'HRMS_candidatePrimarySkills', $keywordsArrayTrimed[$i]],

        ]);

It didn't work. Please Help.

Piyush
  • 3,947
  • 9
  • 36
  • 69

1 Answers1

1

You should simply try this :

// build condition
$condition = ['or'];
foreach ($keywordsArrayTrimed as $keyword) {
    $condition[] = ['like', 'HRMS_candidatePrimarySkills', $keyword];
}

// fetch results
$searchResult = Candidate::find()->where($condition)->all();
soju
  • 25,111
  • 3
  • 68
  • 70