matty Posted March 16, 2007 Share Posted March 16, 2007 Hi, How can i randomly select rows? say for example i have 50 users, 3 of them were online. I only want the 3 online, BUT i want then to be randomly choose. So that everytime i go to the page, it is a different person. Im assuming MySQL numrows has something to do with it but im not quite sure. Thanks, Matt Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted March 16, 2007 Share Posted March 16, 2007 ORDER BY RAND() in your mysql query.... Quote Link to comment Share on other sites More sharing options...
matty Posted March 16, 2007 Author Share Posted March 16, 2007 Explain? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 16, 2007 Share Posted March 16, 2007 Explain? $sql = "SELECT users, users_online FROM your_table WHERE users_online = '{$online}' ORDER BY rand()"; that's what mariner means. Quote Link to comment Share on other sites More sharing options...
matty Posted March 16, 2007 Author Share Posted March 16, 2007 I dont see how it works. Do i do this... $result = mysql_query("SELECT * FROM userdb WHERE id = '$tid' AND online = 'Y' ORDER BY RAND()"); $info = mysql_fetch_array($result); So if there was 3 online that would select the three, and then only pick one at random, correct? Edit, didnt see that post. but im guessing the above is correct. Thanks! =) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.