in Geeky

Symfony – Propel get random data from table

Somebody asked this on IRC so I figured I might as write it down.

Q: How do I get one random row from a table?

A:

$cnt=MyTable::doCount(new Criteria());
$c = new Criteria();
$c->setOffset(rand(1,$cnt));
$mydata=MyTable::doSelectOne($c);

Related Posts

Written By:

Add a Comment