News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Zend Developer Zone:
Fetching multiple random rows from a database
May 06, 2009 @ 11:17:03

On the Zend Developer Zone, a recently posted tutorial looks at fetching multiple random rows from a database table (in a MySQL database).

As a follow up to my earlier article about fetching a single random row from MySQL I will tell you today, how you can fetch multiple random rows from a table without any hassle. Compared to the solution with fetching a single random row, fetching multiple random rows requires some tricks.

The tutorial walks you through the creation of some sample tables, making a simple trigger to keep a "random ID" column in a value range of one to the number of rows (gapless) and a bit of PHP code to select some IDs from the table and the SQL to get their information.

Be sure to check out the comments for mentions of the number of table reads and how optimized certain parts of the queries might be.

0 comments voice your opinion now!
mysql random gapless trigger row multiple database


blog comments powered by Disqus

Similar Posts

Job Posting: Integraclick (Clickbooth.com) Seeks PHP/MySQL Developer (Sarasota/Miami, FL)

Lukas Smith's Blog: Database abstraction mailing list [UPDATE]

PlentyofCode.com: J2EE vs ASP.NET vs PHP

PHPBuilder.com: Creating an Online Survey (Part 2)

CodeForest.net: Key/value tables and how to use them in PHP and MySQL


Community Events

Don't see your event here?
Let us know!


api extension performance opinion version library conference introduction php7 interview symfony2 xdebug example voicesoftheelephpant podcast framework series community laravel release

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework