Jump to content

[SOLVED] Selecting random entries.


Michdd

Recommended Posts

Is there a way to select random entries with a limit and some where clauses? I know I can do some things like.. put some clauses in an array and random get one (eg. ordering by something different each time) and selecting a random number to start as the lower-limit.. But is there a better way to do this?

Link to comment
https://forums.phpfreaks.com/topic/159975-solved-selecting-random-entries/
Share on other sites

Is there a way to select random entries with a limit and some where clauses? I know I can do some things like.. put some clauses in an array and random get one (eg. ordering by something different each time) and selecting a random number to start as the lower-limit.. But is there a better way to do this?

 

Sure, you can use pure MySQL to do this:

 

SELECT * FROM table ORDER BY RAND() LIMIT 10

 

This selects 10 random records from the table.

Is there a way to select random entries with a limit and some where clauses? I know I can do some things like.. put some clauses in an array and random get one (eg. ordering by something different each time) and selecting a random number to start as the lower-limit.. But is there a better way to do this?

 

Sure, you can use pure MySQL to do this:

 

SELECT * FROM table ORDER BY RAND() LIMIT 10

 

This selects 10 random records from the table.

Sorry, this was kind of a waste of a topic.. I should've searched google. I didn't think it was that simple.. Anyway, 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.