Answer the question
In order to leave comments, you need to log in
Is it possible to somehow use MySQL variables in QueryBuilder or DQL?
In general, I use KnpPaginationBundle for pagination and sorting, the following picture comes out:
1. Option with DQL:
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT a, @C:[email protected] +1 FROM (SELECT @row_number := 0) init, GameServerBundle:Server\Server a
LEFT JOIN a.map m1
ORDER BY a.isVip DESC'
);
$query2 = $em->createNativeQuery(
'
SELECT a.*,
s2.id AS id_service,
s2.priority AS `priority`,
@row_number := @row_number := @row_number + 1 AS `top`
FROM (SELECT @row_number := 0) init, `server` a
LEFT JOIN servers_services ss ON (a.id = ss.server_id)
LEFT JOIN service s2 ON (s2.id = ss.service_id)
WHERE a.is_banned = 0
ORDER BY ss.service_id IS NULL, priority DESC
',
$rsm
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question