Jump to content

[SOLVED] Selecting random rows in a table.


matty

Recommended Posts

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

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! =)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.