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 Link to comment https://forums.phpfreaks.com/topic/43007-solved-selecting-random-rows-in-a-table/ Share on other sites More sharing options...
ToonMariner Posted March 16, 2007 Share Posted March 16, 2007 ORDER BY RAND() in your mysql query.... Link to comment https://forums.phpfreaks.com/topic/43007-solved-selecting-random-rows-in-a-table/#findComment-208886 Share on other sites More sharing options...
matty Posted March 16, 2007 Author Share Posted March 16, 2007 Explain? Link to comment https://forums.phpfreaks.com/topic/43007-solved-selecting-random-rows-in-a-table/#findComment-208889 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. Link to comment https://forums.phpfreaks.com/topic/43007-solved-selecting-random-rows-in-a-table/#findComment-208894 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! =) Link to comment https://forums.phpfreaks.com/topic/43007-solved-selecting-random-rows-in-a-table/#findComment-208895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.