Forums

Order by rand() in Model query

megana 15 Jun, 2015
How to get some random entries from the database?

I put RAND() in the Order field, but the result is this:

ORDER BY `model`.`RAND`()
GreyHead 17 Jun, 2015
Hi megana,

I don't think that you can do this without hacking the CC code. If you are loading all the records then you could shuffle them using PHP but that won't work if you are only loading a sub-set.

Bob
megana 18 Jun, 2015
Thanks Bob, that's really annoying! Luckily I don't have many records total, so pulling them all and then using array_rand() or shuffle() in the pre display processing should work in this case.
This topic is locked and no more replies can be posted.