* Thus wrote Daniel Bray ([EMAIL PROTECTED]): > Ok, I have looked through the archives on both MySQL and PHP's lists, but > I have not seen this asked or mentioned. Weird, I thought this would be a > common thing. Is there a better way to randomly select a table from a > database, than what I have come up with:
I dont see how finding a random table could be a common thing. > > <?php > srand ((float) microtime() * 10000000); You don't need to call srand with php >= 4.2.0. > $table_array = array (); > mysql_connect("localhost", "mysql_user", "mysql_password"); > $result = mysql_list_tables("database_name"); > > for ($i = 0; $i < mysql_num_rows($result); $i++) > { > $table_name = mysql_tablename($result, $i); > array_push ($table_array , "$table_name"); > } > > $rand_keys = array_rand ($table_array, 2); Instead of looping through all the tables and building an array you can do something like: $n = mysql_num_rows($result); $seek = mt_rand(0, $n-1); mysql_data_seek($result, $seek); Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php