Random selections from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kippy
Forum Commoner
Posts: 84
Joined: Wed Jun 07, 2006 8:25 pm

Random selections from database

Post by kippy »

What is the easiest and safest way to pull 5 random items from my database. I am thinking the rand function can be used in some way, but I am not sure how safe etc this type of action will be? Thanks for any advice. :D
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Random selections from database

Post by onion2k »

"ORDER BY rand LIMIT 5" I'd say. It's certainly the easiest.
kippy
Forum Commoner
Posts: 84
Joined: Wed Jun 07, 2006 8:25 pm

Re: Random selections from database

Post by kippy »

That is where I was headed but just wanted to make sure I wasn't missing anything. Thanks.
Post Reply