Re: randomly select a table, better way?
| From: | Daniel Bray | Date: | Tue, 02 Sep 2003 00:17:20 +0000 |
| Subject: | Re: randomly select a table, better way? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-161403@lists.php.net to get a copy of this message | ||
On Mon, 01 Sep 2003 22:49:55 +0000, Curt Zirzow wrote:
>
> 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
So then the total code would be:
<?
$mysqlconnect = mysql_connect("localhost", "mysqladmin",
"i.hate.microsoft");
$result = mysql_list_tables("Bookmarks");
$n = mysql_num_rows($result);
$seek = mt_rand(0, $n-1);
$random_table = mysql_data_seek($result, $seek);
echo "<br><br>The randomly slected table
was<b>$random_table</b><br><br>";
?>
If so, then this does not work for me. All I get is $random_table == 1. If not,
then what am I missing.
Thanks for your quick response,
DB