Requête SQL query builder
Bonjour à tous,
J'effectue une répétition pour récupérer la bonne données dans un tableau. Ma requête est bonne mais je souhaite généraliser cette répétition par n au lieu d'écrire beaucoup de lignes mais je ne trouve pas la solution.
Pourriez vous m'aider ?
Bien à vous.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
public function findByProduct($arr) {
return $this->createQueryBuilder('p')
->select("p, partial c.{id, name}")
->leftJoin('p.company', 'c')
->andWhere('p.name LIKE :name')
->orWhere('p.name LIKE :name1')
->orWhere('p.name LIKE :name2')
->orWhere('p.name LIKE :name3')
->orWhere('p.name LIKE :name4')
->setParameter('name', $arr[0])
->setParameter('name1', $arr[1])
->setParameter('name2', $arr[2])
->setParameter('name3', $arr[3])
->setParameter('name4', $arr[4])
->getQuery()
->getArrayResult();
} |