lundi 1 février 2016

mysql select rand() runing slow

I have 12 queries which run in one page, one for each month. They select one random user for each month. It's running pretty slow, is there a way to speed it up? Here's the query:

$result = mysql_query('SELECT * FROM monthly where month = "jan" and a="0" ORDER BY RAND() LIMIT 0,1;');

while($row = mysql_fetch_array($result))
{
$id = $row['id'];
$ip = $row['ip'];
$title = $row['tile'];
$user = $row['user'];
$email = $row['email'];
$phone = $row['phone'];
    }

    .
    .
    .
    .
    .
$result = mysql_query('SELECT * FROM monthly where month = "dec" and a="0" ORDER BY RAND() LIMIT 0,1;');

while($row = mysql_fetch_array($result))
{
$id = $row['id'];
$ip = $row['ip'];
$title = $row['tile'];
$user = $row['user'];
$email = $row['email'];
$phone = $row['phone'];
    }




Aucun commentaire:

Enregistrer un commentaire