I currently use EZSQL class in php to query the MySQL database. I am trying to grab random records from the database, but I would like to know if I could randomize the results via php instead of the sql query itself. The query currently looks like this:
$results = $db->get_results("SELECT * FROM table ORDER BY RAND()");
foreach($results AS $result)
{
//code here
}
Instead could I just grab the results from the db then randomize it via php? If so, how can I do this?
shuffleLIMITinvolved, you will go back to SQL'sRAND(), which works just fine. If you thinkRAND()is a problem for large databases (not true) then you will have to use aLIMITto not select billions of rows. So there you have it:ORDER BY RAND()is your only choice.