Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 11th, 2003, 09:35 AM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default random records from database

Hi,

Could someone help me with code to get me started in getting 4 random records from a database table?

Thanks

HammR

  #2 (permalink)  
Old December 11th, 2003, 02:03 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what database? If you're using mysql, you can use an "order by rand()" clause in your select query:

SELECT * FROM table ORDER BY RAND() LIMIT 4;


Take care,

Nik
http://www.bigaction.org/


Similar Threads
Thread Thread Starter Forum Replies Last Post
csv with multiple records in random order biztalk xs2bharat Biztalk 0 May 2nd, 2007 07:09 AM
random numbers from/to database HammR PHP Databases 10 January 14th, 2005 12:08 PM
ongoing problem with random records....HELP! ps124 ASP.NET 1.0 and 1.1 Basics 0 March 26th, 2004 05:35 PM
help with random records ps124 ASP.NET 1.0 and 1.1 Basics 0 March 14th, 2004 10:57 PM
Generating 5 unique random records from a database ps124 ASP.NET 1.0 and 1.1 Basics 2 March 8th, 2004 05:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.