Re: Random Access to a Database

From: Date: Thu, 03 Aug 2000 22:51:46 +0000
Subject: Re: Random Access to a Database
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-1536@lists.php.net to get a copy of this message
Thanks for the help Zak - it worked perfectly. Thank-you to everyone else who inputed to this topic. Much appreciated. ----- Original Message ----- From: "Zak Greant" <zak@nucleus.com> To: <php-windows@lists.php.net>; "Tom Peck" <tompeck@paradise.net.nz> Sent: Thursday, August 03, 2000 7:01 PM Subject: Re: [PHP-WIN] Random Access to a Database > > I am using MySQL. How would this be possible? > > In MySQL 3.23, you can do: SELECT * FROM table_name ORDER BY RAND() > > In previous versions you need to be more resourceful. > > If you have a auto incrementing index you can do this (untested code) > > Assuming that your auto_inc field is called id... > SELECT *, floor(count(id) * rand(now()) + 1) as rand_id FROM table_nameWHERE > id=rand_id > > You can also do a query that returns the count of the table, use PHP's > random functions to generate a random number and then query for that entry > in the database. > > Good Luck! > > Zak > > PS - This question is better suited to the PHP-DB mailing list > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.windows (#1536) next »