Randomy mySQL picker

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
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Randomy mySQL picker

Post by bla5e »

How do I make a code that will RANDOMLY pick a user from a mySQL database?
Im using my forums `users` table for the database to be randomly picked from becuase im holding a competition for when I reach 100 members, I will be giving away money. Well I want PHP to randomly pick the member when I run the script but I have no idea where to start, please help with either an Idea or a code.

Thanks!
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

SELECT * FROM `users` ORDER BY rand() LIMIT 1 ;
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

oh, i didnt know there was a mysql query for it :oops:
thanks
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

The MySQL documentation can do wonders...

Here's the search: http://dev.mysql.com/doc/mysql/search.p ... nd&lang=en

Related section (found from search): http://dev.mysql.com/doc/mysql/en/mathe ... tions.html

It's in there.
Post Reply