Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony] order by rand()
dopelganger
post
Post #1





Grupa: Zarejestrowani
Postów: 236
Pomógł: 0
Dołączył: 27.10.2012

Ostrzeżenie: (0%)
-----


cześć

wszystko ładnie pięknie (IMG:style_emoticons/default/smile.gif) a ja nie wiem :/
jak pobrać 4 losowe rekordy z bazy?
przewertowałem google ale wszędzie jakieś niejasności ,,,

  1. $rand = $em->getRepository('ArticleBundle:Article')->findBy(
  2. array('id'=>'DESC'),
  3. 4
  4. );


prosze o pomoc
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
M4ver
post
Post #2





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 22.03.2014

Ostrzeżenie: (0%)
-----


Spróbuj :
http://doctrine-orm.readthedocs.org/en/lat...native-sql.html
Go to the top of the page
+Quote Post
dopelganger
post
Post #3





Grupa: Zarejestrowani
Postów: 236
Pomógł: 0
Dołączył: 27.10.2012

Ostrzeżenie: (0%)
-----


Cytat(M4ver @ 20.05.2015, 12:45:07 ) *



mam coś takiego:

  1. $rsm = new ResultSetMapping();
  2. $query = $this->em->createNativeQuery('SELECT * FROM article ORDER BY RAND()', $rsm);
  3. $rand = $query->getResult();


mam byka:

Notice: Undefined property:....Bundle\Controller\DefaultController::$em

co mam wstawić pod em ?

($em = $this->getDoctrine()->getManager()(IMG:style_emoticons/default/questionmark.gif) (IMG:style_emoticons/default/questionmark.gif) nie działa,

Ten post edytował dopelganger 20.05.2015, 13:52:22
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.10.2025 - 00:53