SELECT DISTINCT id FROM table ORDER BY RAND() LIMIT 3
$db = mysqli($dbHost, $dbUser, $dbPassword, $dbName); $result = $db->query('SELECT DISTINCT id FROM tabla ORDER BY RAND() LIMIT 3'); if(is_object($result)) { $var = $result->fetch_all(MYSQLI_ASSOC); $result->free();} echo 'Variable 1: ' . $var[0]['id'] . '<br/>' . 'Variable 2: ' . $var[1]['id'] . '<br/>' . 'Variable 3: ' . $var[2]['id'] . '<br/>';
variable1 = $var[0]['id'];