View Full Version : Possible to Select a Random User from Logged on Users?
Jason92s
03-16-2011, 03:34 PM
We're running a contest and would like to select a random user from the users that are logged on at a specific time on our site. Haven't been able to find a way to do this. Any help is appreciated.
SamirDarji
03-23-2011, 04:14 AM
I don't know much about this sort of thing, but am starting to research it since I need something similar (random user from ones logged in last week/month).
In theory, you should be able to run a query that will query all the users online at a particular time. In fact, this is already being done by the who's online, so it's just a matter of taking all those user numbers putting them into an array and then selecting a random element from that array, which would correspond to a random user. You could probably even make a cron job that will automatically run the script and email you the username.
Lynne
03-23-2011, 04:08 PM
Yep. Look in the $users query for the forum.php page to get an idea of how to find out who is online. You can make that query much simpler for your purposes since you only need the userid. Then pick a random user from that array.
SamirDarji
03-23-2011, 04:50 PM
Thank you for the post Lynne. :) I'm not a programmer and it was really late when I posted that, lol. Good to know my brain still works at night.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.