Answer the question
In order to leave comments, you need to log in
CreateQuery how to give additional condition andWhere?
Good afternoon, how can I make an additional condition in createQuery? I want to add filtering by account type. In the request itself, for now, it just picks up by the date of the sessions. It is considered successful with 0 message - delivered specifically for debugging for the time being.
$sessionCountData = $this->em->createQuery("
SELECT DATE_FORMAT(STR_TO_DATE(l.field3, '%d.%m.%Y %H:%i:%s'), '$format') as date,
COUNT(l.id) as session_count,
SUM(IF(l.field6 >= :min_message_count, 1, 0)) as success_session_count
FROM Site\Models\Log l
JOIN Site\Models\User u WITH u.id = l.field10 AND l.type = 'userGoneOffline'
WHERE STR_TO_DATE(l.field2, '%d.%m.%Y %H:%i:%s') > :start_date AND STR_TO_DATE(l.field3, '%d.%m.%Y %H:%i:%s') <= :end_date AND u.signupDate BETWEEN :signup_from AND :signup_to
GROUP BY date
");
if($form->checkedPremiumValue){
$sessionCountData->andWhere('ченить');
}
Answer the question
In order to leave comments, you need to log in
public function getUsers($name = null)
{
$em = $this->getEntityManager();
$parameters = [':id' => 2];
$dql = 'SELECT u from User u where u.id > :id';
if($name){
$dql .= ' and u.name = :name';
$parameters[':name']=$name;
}
return $em
->createQuery($dql)
->setParameters($parameters)
->getResult();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question