Hi everyone
I'm trying to get a random result from a query. I don't want to use ORDER BY RAND() LIMIT 1 because it needs a query for itself and i'm afraid that on a large table it might get slow. So I want to use the array_rand function but I'm not sure how to put the results of the query into the array.
I use the code from php.net
srand((float) microtime() * 10000000);
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";
but instead of "Neo", "Morpheus" etc I want to have the values of a field from the results. I tried something like
$input = array();
while ($row2 = mysql_fetch_array($result)) {
$input[] = $row2['myfield'];
}
but it doesn't work.
Maybe this makes you laugh but please help me out!