I would like to get the value of the column uid
from all rows where the value of the column city
is london
.
I have tried it like this:
JavaScript
x
$this->getDoctrine()->getRepository(Personal::class)->findOneBy(['city' => 'london']);
but then I get an object from only 1 row. What I need is simply an array that looks kind of like this:
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
Advertisement
Answer
Use findBy instead findOneBy. It gives you array of entities.
But you can`t define, which column should be fetched. For that you should use DQL where you define what should be fetched.
For example with query builder:
JavaScript
$queryBuilder = $this->createQueryBuilder()
->select('p.uid')
->from(Personal::class, 'p')
->where('p.city = 'london'');
$uids = $queryBuilder->getQuery()->getResult();