How to select randomly with doctrine

前端 未结 13 1035
耶瑟儿~
耶瑟儿~ 2020-11-27 20:21

Here is how I query my database for some words

$query = $qb->select(\'w\')
    ->from(\'DbEntities\\Entity\\Word\', \'w\')
    ->where(\'w.indiction         


        
13条回答
  •  长情又很酷
    2020-11-27 20:28

    Or you could do this -->

    $words = $em->getRepository('Entity\Word')->findAll();
    shuffle($words);
    

    Of course this would be very inefficient if you have many records so use with caution.

提交回复
热议问题