![]() |
|
Snippets |
|
More a PHP trick than symfony's one, but as you can't with propel randomize order of results, just do:
$c = new Criteria() ... fill your criteria there ... $result = MyTablePeer::doSelect($c); shuffle($result);
obvious? sorry, seen someone asking on IRC once :D
Comments on this snippet
You should't do that if your table contains more than a few records. It'll load all your rows into memory.
There were some other solutions suggested on the Propel mailing list, like here: http://propel.tigris.org/servlets/ReadMsg?list=users&msgNo=3866 http://propel.tigris.org/servlets/ReadMsg?list=users&msgNo=2965
So try something like that:
or that:
Thanks Romain and Martin for useful info! :)
Hoho thought order by rand() wasn't working with propel... thanks for the info, this snipeet stuff is awesome collaborative tool!
Does anybody know of an easy way to extend this snipeet to paginate a random result set?
IMHO, the setOffset in Martin's snippet should be : <code>$phoneCriteria->setOffset(rand(0,$phoneCount-1));</code>
Very cool snippet indeed ! :) THanks guys... But I have to say a greater "thanks" to martin as his code is a little better ;)
mysql has something like
order by rand()
i think..