PHP:
1
| <?function makepicture_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000);}function getPictureRandom($gallery) { srand(makepicture_seed()); $sql = "SELECT * FROM galleryphoto WHERE galleryid='$gallery'"; $result = mysql_query($sql); $total = mysql_num_rows($result); if ($total) { // Generate a random number between 0 and $num_results - 1 $rand = mt_rand (0, $total); // Jump to the random row mysql_data_seek ($result, $rand); // Fetch the selected row $photo = mysql_fetch_assoc($result); } mysql_free_result($result); return $photo;}?> |
Kan iemand mischien zien waarom deze functie getRandomPicture alleen het laatste plaatje -1 laatzien en niet een random plaatje?