So far, I think doctrine doesn't have a way of selecting a random row. So I am thinking I have a query to get the count of rows
// pseudo code
$count = SELECT COUNT(i) FROM Item i WHERE ...
Then have a real query to get the item using a random offset from PHP put into setFirstResult
$item = (SELECT i FROM Item WHERE ...)->setMaxResults(1)->setFirstResult(rand(0, $count))->getSingleResult()
Question is, my rand()
do I start from 0 or 1? Then the end? $count
or $count-1
?
->setMaxResults(1)->setFirstResult(rand(1,$count))
? – Gotama