samedi 8 octobre 2016

Generate random MySQL rows quickly and run same sql query multiple times

I have found an example where it generates a random row quickly: MySQL select 10 random rows from 600K rows fast

Now I would like to run that query 10 times but I'm getting exactly same output instead of different rows. Any ideas how to solve this:

Here is my code:

<?php
    for ($e = 0; $e <= 14; $e++) {
         $sql_users = "SELECT user_name, user_age, country, age_from, age_to, gender, profile_image, gender_search, kind_of_relationship
                          FROM users AS r1 JOIN
                               (SELECT CEIL(RAND() *
                                             (SELECT MAX(id)
                                                FROM users)) AS id)
                                AS r2
                         WHERE r1.id >= r2.id
                         ORDER BY r1.id ASC
                         LIMIT 1";
         $statement6 = $dbConn->prepare($sql_users);
         $statement6->execute();
         more = $statement6->fetch(PDO::FETCH_BOTH);
?>

    <?php echo $more['user_name'];?>

<?php } ?>




Aucun commentaire:

Enregistrer un commentaire