Elxis CMS Forum

Support => Elxis 2008 developers guide => Topic started by: datahell on October 05, 2007, 22:45:30

Title: Random ordering and ADODB
Post by: datahell on October 05, 2007, 22:45:30
If you wish to order randomly the results from the database then dont use "ORDER BY RAND()" as it is a native mysql function and only works on Elxis under MySQL. In this case you should use the $random variable of ADODB which is set automatically for every database type.

Instead of this:

$query = "SELECT........."
."\n ORDER BY RAND()";

Use this:

$randfunc = $database->_resource->random;
$query = "SELECT........."
."\n ORDER BY ".$randfunc;

The randomize function for MySQL is RAND() and for Postgres is RANDOM()