Re: random rows...what about tables

From: Date: Tue, 17 Dec 2002 13:54:37 +0000
Subject: Re: random rows...what about tables
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-24225@lists.php.net to get a copy of this message
At 23:38 17-12-02 +1000, Bruce Levick wrote:
Bruce Levick - Vivamotion Been searching for an answer to selecting a random table and then a random row within the selected table. I have this code which successfully selects a random row within a hard coded table. But just can't get the random table working. <?php //trying to select all tables from the database portfolio........pfff $alltables = mysql_list_tables("portfolio"); //trying to get the array value of the alltables...there are 4 tables in the database. So as far as I know the value of $alltables should be 3. (0table, 1table, 2table, 3table) $randtabnum = array($alltables);
$randomtabel = array_rand($alltables);
// this selects everything from the Illustrations table. I need to make the FROM table_name a random selection $all = mysql_query("SELECT * FROM Illustrations"); //acquires total rows $totalRows_Recordset1 = mysql_num_rows($all); // selects random row from total rows $rndm = mysql_query("SELECT * FROM Illustrations ORDER BY RAND() LIMIT 4,$totalRows_Recordset1"); if (!$rndm) {
      echo("<P>Error performing query: " .
           mysql_error() . "</P>");
      exit();
    }
$randrow = mysql_fetch_array($rndm); ?> Anybody see the solution?? Winxp Pro, php 4.2.2 Mysql 3.2 Cheers -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.db (#24225) next »