You have to do it like this:

    'ORDER BY' => 'rand()',

Note that 'rand()' is in quotes, to send this string to MySQL and call the SQL rand() function – otherwise, you'd call the rand() function in PHP and send a random number to MySQL.

In general this is a bad idea, though, since this doesn't mean "select a random row and return it" – it means "select all rows, order them randomly, then return the first one", which is going to quickly become slow if you have more than a couple thousand of rows.

The page_random column John suggested in used for MediaWiki's built-in random page functionality, and a much better idea. You would use something like:

    'page_random >= ' . wfRandom(),

…in the WHERE condition. See how it's used in MediaWiki:
https://phabricator.wikimedia.org/diffusion/MW/browse/master/includes/specials/SpecialRandompage.php;4de667f3c2dd2fea0f246a313a9ed848a793ed2f$116


--
Bartosz Dziewoński

_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to