ehm.. penso che non hai spulciato tanto bene la rete visto che è l'ultimo esempio (il primo in ordine di lettura) insertito sulla pagina della funzione rand() di PHP...
Codice PHP:
<?php
$query = "SELECT `id` FROM [TABLE]";
$result = mysql_query($query, $link);
$num = mysql_num_rows($result);
if ($num > 0) {
// Array the ID's...
$id_array = array();
while ($row = mysql_fetch_assoc($result)) {
$id_array []=$row["id"];
}
$query = "SELECT * FROM [TABLE] WHERE `id`=".$id_array[rand(0, (count($id_array)-1))];
$result = mysql_query($query, $link);
$row = mysql_fetch_assoc($result);
// ...
}
?>
oppure estrai random un record direttamente da mysql..
Codice PHP:
SELECT ... FROM my_table ORDER BY RAND() LIMIT 1