Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.